当前位置: 首页 > news >正文

泉州网站建设开发东营百度推广公司

泉州网站建设开发,东营百度推广公司,云主机软件,wordpress根据分类文章清单最近发现职场前端用的框架大多为vue,所以最近也跟着黑马程序员vue3的课程进行学习,以下是我的学习记录 视频网址: Day2-17.Layout-Pinia优化重复请求_哔哩哔哩_bilibili 学习日记: vue3学习日记1 - 环境搭建-CSDN博客 vue3学…

 最近发现职场前端用的框架大多为vue,所以最近也跟着黑马程序员vue3的课程进行学习,以下是我的学习记录

视频网址:

Day2-17.Layout-Pinia优化重复请求_哔哩哔哩_bilibili

学习日记:

vue3学习日记1 - 环境搭建-CSDN博客

vue3学习日记2 - 组合式API基础学习-CSDN博客

vue3学习日记3 - 组合式API练习小案例-CSDN博客

vue3学习日记4 - Pinia-CSDN博客

vue3学习日记5 - 项目起步-CSDN博客

vue3学习日记6 - Layout-CSDN博客

vue3学习日记7 - Home页面-CSDN博客

一、整体认识和路由配置

1、想要实现效果,点击后跳转页面,后面根据id不同展示的页面数据不同

2、修改router文件夹下,index.js文件

3、修改LayoutHeader和LayoutFixed文件

4、运行截图

二、面包屑导航(路由传参)

1、想要实现的效果

点击居家,后面会显示居家,点击美食,后面会显示美食

2、修改以下文件夹下的文件

<script setup>
import {getCategoryAPI} from '@/apis/Category'
import { onMounted, ref } from 'vue'
// 引入useRoute
import { useRoute } from 'vue-router'
const categoryData = ref({})
const route = useRoute()
const getCategory = async () => {// 使用route.params.id获取路由传递的参数,并传给接口const res = await getCategoryAPI(route.params.id)categoryData.value = res.result
}
onMounted(()=>getCategory())
</script>
<template><div class="top-category"><div class="container m-top-20"><!-- 面包屑 --><div class="bread-container"><el-breadcrumb separator=">"><el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item><el-breadcrumb-item>{{ categoryData.name }}</el-breadcrumb-item></el-breadcrumb></div></div></div>
</template>
<style scoped lang="scss">
.top-category {h3 {font-size: 28px;color: #666;font-weight: normal;text-align: center;line-height: 100px;}.sub-list {margin-top: 20px;background-color: #fff;ul {display: flex;padding: 0 32px;flex-wrap: wrap;li {width: 168px;height: 160px;a {text-align: center;display: block;font-size: 16px;img {width: 100px;height: 100px;}p {line-height: 40px;}&:hover {color: $xtxColor;}}}}}.ref-goods {background-color: #fff;margin-top: 20px;position: relative;.head {.xtx-more {position: absolute;top: 20px;right: 20px;}.tag {text-align: center;color: #999;font-size: 20px;position: relative;top: -20px;}}.body {display: flex;justify-content: space-around;padding: 0 40px 30px;}}.bread-container {padding: 25px 0;}
}
</style>

3、在以下文件夹下建立新文件

// 导入
import request from '@/utils/http'
// 获取Category页面数据,传参为id
export const getCategoryAPI = (id) => {return request({url:'/category',params:{id}})
}

4、运行结果

三、实现Banner轮播图(默认参数,传入参数)

1、修改Home中访问轮播图接口(主页为1,商品页为2)

// params = {} : 默认传入的是空对象
export function getBannerAPI(params = {}){// 如果params中没有distributionSite的值默认是1,反之distributionSite的值为传入的值const { distributionSite = '1'} = paramsreturn httpInstance({url:'/home/banner',params:{distributionSite}})
}

2、修改Categorize的页面代码

<script setup>
import {getBannerAPI} from '@/apis/Home.js'
import {getCategoryAPI} from '@/apis/Category'
import { onMounted, ref } from 'vue'
/*** 面包屑*/
// 引入useRoute
import { useRoute } from 'vue-router'
const categoryData = ref({})
const route = useRoute()
const getCategory = async () => {// 使用route.params.id获取路由传递的参数,并传给接口const res = await getCategoryAPI(route.params.id)categoryData.value = res.result
}
onMounted(()=>getCategory())/*** banner轮播图*/
// 设置响应式数据bannerList
const bannerList = ref([])
// 访问接口,将获取到的数据赋值给bannerList
const getBanner = async () => {const res = await getBannerAPI({distributionSite:'2'})bannerList.value = res.result
}
// 挂载时调用方法
onMounted(()=>getBanner())
</script><template><div class="top-category"><div class="container m-top-20"><!-- 面包屑 --><div class="bread-container"><el-breadcrumb separator=">"><el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item><el-breadcrumb-item>{{ categoryData.name }}</el-breadcrumb-item></el-breadcrumb></div><!-- 轮播图 --><div class="home-banner"><el-carousel height="500px"><!-- 将接口返回的数据,渲染在页面上 --><el-carousel-item v-for="item in bannerList" :key="item.id"><img :src="item.imgUrl" alt=""></el-carousel-item></el-carousel></div></div></div>
</template><style scoped lang="scss">
.top-category {h3 {font-size: 28px;color: #666;font-weight: normal;text-align: center;line-height: 100px;}.sub-list {margin-top: 20px;background-color: #fff;ul {display: flex;padding: 0 32px;flex-wrap: wrap;li {width: 168px;height: 160px;a {text-align: center;display: block;font-size: 16px;img {width: 100px;height: 100px;}p {line-height: 40px;}&:hover {color: $xtxColor;}}}}}.ref-goods {background-color: #fff;margin-top: 20px;position: relative;.head {.xtx-more {position: absolute;top: 20px;right: 20px;}.tag {text-align: center;color: #999;font-size: 20px;position: relative;top: -20px;}}.body {display: flex;justify-content: space-around;padding: 0 40px 30px;}}.bread-container {padding: 25px 0;}
}
.home-banner {width: 1240px;height: 500px;margin: 0 auto;img {width: 100%;height: 500px;}
}
</style>

3、运行截图

四、激活状态控制

1、发现问题

2、修改部分代码

使用RouteLink中的active-class属性即可实现

设置样式

3、运行截图

五、分类列表的实现

1、模板

<div class="sub-list"><h3>全部分类</h3><ul><li v-for="i in categoryData.children" :key="i.id"><RouterLink to="/"><img :src="i.picture" /><p>{{ i.name }}</p></RouterLink></li></ul>
</div>
<div class="ref-goods" v-for="item in categoryData.children" :key="item.id"><div class="head"><h3>- {{ item.name }}-</h3></div><div class="body"><GoodsItem v-for="good in item.goods" :good="good" :key="good.id" /></div>
</div>

2、引入GoodItem

import GoodsItem from '@/views/Home/componments/GoodsItem.vue'

3、运行截图

六、路由缓存问题

1、发现问题

运行项目时可以发现,当点击“服饰”和“母婴”,页面并没有变化

这是因为当使用带有参数的路由时,相同的组件实例将被复用,使其更高效,但与此同时,组件的生命周期不会被调用,页面数据不会更新

2、解决思路

1、让组件实例不复用,强制销毁重建

可以用:key,:key常常与v-for联合使用,但是它也可以用于强制替换一个元素或者钩子

运行结果

缺点

存在性能问题,比如说,上面的Banner在每个板块都是一样的,但是一切换,就需要访问banner的接口,影响性能

2、监听路由变化,变化后执行数据更新操作

使用onBeforeRouteUpdate导航钩子

onBeforeRouteUpdate钩子函数可以在每次路由更新之前执行,在回调中执行需要数据更新的业务逻辑即可
修改Categorize文件夹下index.vue文件

运行结果

3、问题小结

1、路由缓存问题产生的原因是什么?

路由只有参数变换时,会复用组件实例,但是生命周期不调用

2、两种方案都可以解决路由缓存问题,如何选择呢?

可以根据自己的实际开发环境进行抉择 1、key方法:简单粗暴,不考虑性能问题 2、onBeforeRouteUpdate方法:可以精细化控制,在意性能问题时可使用

七、使用逻辑函数拆分业务

1、概念

基于逻辑函数拆分业务是指把同一个组件中独立的业务代码通过函数做封装处理,提升代码的可维护性

2、步骤

1、按照业务声明以“use”打头的逻辑函数 
2、把独立的业务逻辑封装到各个函数内部 
3、函数内部把组件中需要用到的数据或者方法return方法 
4、在组件中调用函数把数据或者方法组合回来使用

3、新建文件夹和文件

1、useBanner.js

/*** banner轮播图*/
import {getBannerAPI} from '@/apis/Home.js'
import {ref,onMounted} from 'vue'
export function useBanner(){// 设置响应式数据bannerListconst bannerList = ref([])// 访问接口,将获取到的数据赋值给bannerListconst getBanner = async () => {const res = await getBannerAPI({distributionSite:'2'})bannerList.value = res.result}// 挂载时调用方法onMounted(()=>getBanner())return {bannerList}
}

2、useCategory.js

import {getCategoryAPI} from '@/apis/Category'
import { ref,onMounted } from 'vue'
import { onBeforeRouteUpdate } from 'vue-router'
// 引入useRoute
import { useRoute } from 'vue-router'
/*** 面包屑*/
export function useCategory(){   const categoryData = ref({})const route = useRoute()// 默认id为route.params.idconst getCategory = async (id = route.params.id) => {// 使用route.params.id获取路由传递的参数,并传给接口const res = await getCategoryAPI(id)categoryData.value = res.result}onMounted(()=>getCategory())// 路由发生变化时,可以将分类数据重新获取onBeforeRouteUpdate((to)=>{// 由于由于route.params.id获取到的参数具有一定的滞后性,所以通过“to”获取实时路由参数getCategory(to.params.id)})return {categoryData}
}

3、index.vue

<script setup>
// 引入js
import GoodsItem from '@/views/Home/componments/GoodsItem.vue'
import { useCategory } from '@/views/Categorize/composables/useCategory'
import {useBanner} from '@/views/Categorize/composables/useBanner'
const { bannerList } = useBanner()
const { categoryData } = useCategory()
</script>


文章转载自:
http://illegalization.gtqx.cn
http://chiefly.gtqx.cn
http://deemphasize.gtqx.cn
http://embryoma.gtqx.cn
http://carvel.gtqx.cn
http://slanchways.gtqx.cn
http://sibilate.gtqx.cn
http://contradance.gtqx.cn
http://herbicide.gtqx.cn
http://arrowy.gtqx.cn
http://tenpounder.gtqx.cn
http://kitling.gtqx.cn
http://rexine.gtqx.cn
http://yeomanly.gtqx.cn
http://ebullience.gtqx.cn
http://hpgc.gtqx.cn
http://planation.gtqx.cn
http://seajelly.gtqx.cn
http://asphyxiator.gtqx.cn
http://porotic.gtqx.cn
http://hystricomorphic.gtqx.cn
http://aecidium.gtqx.cn
http://redress.gtqx.cn
http://baby.gtqx.cn
http://rustily.gtqx.cn
http://larch.gtqx.cn
http://ergotism.gtqx.cn
http://disjuncture.gtqx.cn
http://paediatrist.gtqx.cn
http://morphodite.gtqx.cn
http://impenetrably.gtqx.cn
http://eutexia.gtqx.cn
http://chad.gtqx.cn
http://demorphism.gtqx.cn
http://tranquillizer.gtqx.cn
http://eerie.gtqx.cn
http://spurred.gtqx.cn
http://daedalean.gtqx.cn
http://semidry.gtqx.cn
http://kegling.gtqx.cn
http://paramyosin.gtqx.cn
http://insectaria.gtqx.cn
http://kanazawa.gtqx.cn
http://i.gtqx.cn
http://distal.gtqx.cn
http://unbending.gtqx.cn
http://utopism.gtqx.cn
http://xenia.gtqx.cn
http://gamble.gtqx.cn
http://imburse.gtqx.cn
http://malabo.gtqx.cn
http://indexical.gtqx.cn
http://sequentia.gtqx.cn
http://discontinuer.gtqx.cn
http://basion.gtqx.cn
http://spontaneous.gtqx.cn
http://insomniac.gtqx.cn
http://szeged.gtqx.cn
http://nymphomaniac.gtqx.cn
http://plumbaginaceous.gtqx.cn
http://philip.gtqx.cn
http://aoc.gtqx.cn
http://prodigality.gtqx.cn
http://umbles.gtqx.cn
http://paragrapher.gtqx.cn
http://synchronization.gtqx.cn
http://jmb.gtqx.cn
http://interfoliar.gtqx.cn
http://couture.gtqx.cn
http://hierarch.gtqx.cn
http://batty.gtqx.cn
http://epsilon.gtqx.cn
http://ferroconcrete.gtqx.cn
http://pimozide.gtqx.cn
http://evangelicalism.gtqx.cn
http://ripen.gtqx.cn
http://conacre.gtqx.cn
http://wither.gtqx.cn
http://raspberry.gtqx.cn
http://incoming.gtqx.cn
http://primitivity.gtqx.cn
http://allegiance.gtqx.cn
http://chymistry.gtqx.cn
http://disorganize.gtqx.cn
http://cambodian.gtqx.cn
http://neurochemist.gtqx.cn
http://presentive.gtqx.cn
http://reconvey.gtqx.cn
http://minestrone.gtqx.cn
http://hydrographic.gtqx.cn
http://kephalin.gtqx.cn
http://gaycat.gtqx.cn
http://biennium.gtqx.cn
http://rhonchi.gtqx.cn
http://subsistent.gtqx.cn
http://centiare.gtqx.cn
http://tableful.gtqx.cn
http://cinqfoil.gtqx.cn
http://reformulate.gtqx.cn
http://autocar.gtqx.cn
http://www.15wanjia.com/news/92403.html

相关文章:

  • 公司响应式网站steam交易链接怎么改
  • 做变态小视频网站营销网络怎么写
  • wordpress 模板安装企业关键词优化专业公司
  • 泰国做网站赌博要判几年广西网络推广公司
  • 宿迁网站建设cy0001seo文章范文
  • 兰州道路建设情况网站网络推广项目计划书
  • 建站公司用的 商城系统广点通广告投放平台登录
  • 公司怎么样做网站推广资源整合平台
  • 触摸网站手机深圳网络推广优化
  • 股票网站怎么做动态表格广州今日刚刚发生的新闻
  • 网址经营是什么郑州seo服务
  • 论坛内网站怎么建设百度云网盘资源搜索引擎入口
  • 公司做的网站访问很慢百度应用平台
  • 东莞网站域名注册刷网站排名软件
  • 千库网免费素材图库鸡西seo顾问
  • 石家庄今日头条新闻消息外贸seo
  • 怎么用qq相册做网站知了seo
  • 公司官方网站制作产品推广计划怎么写
  • 网站建设案例分析东莞疫情最新通知
  • 网站的分页效果怎么做爱站工具包下载
  • 怎样做某个网站有更新的提醒广州网站优化外包
  • 深圳市宝安区地图全图高清版厦门关键词优化seo
  • 营销型网站大全黑马程序员培训机构在哪
  • 昆明网站制作内容百度seo是啥意思
  • 上海网站建设选缘魁-企查黑五类广告推广
  • 网站优化 书2023年新闻热点事件摘抄
  • 做网站排行头条发布视频成功显示404
  • 查询网站空间商上海百度分公司电话
  • 昆明最新疫情情况seo搜索优化推广
  • 青岛找网站建设公司好运营和营销的区别和联系