首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,087 阅读
2
类的加载
742 阅读
3
Spring Cloud OAuth2.0
726 阅读
4
SpringBoot自动装配原理
691 阅读
5
集合不安全问题
589 阅读
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
FastApi
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
Mybatis
Spring
html5
蘇阿細
累计撰写
390
篇文章
累计收到
4
条评论
首页
栏目
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
FastApi
页面
统计
关于
搜索到
94
篇与
的结果
2022-07-17
其他Composition API
1. shallowReactive与shallowRefshallowReactive:只处理对象最外层属性的响应式(浅响应式)shallowRef:只处理基本数据类型的响应式,不进行对象类型的响应式处理使用场景:如果有一个对象数据,结构比较深,但变化时只是第一层(外层)属性变化 ---> shallowReactive如果有一个对象数据,后续功能不会修改该对象中的属性,而是生成一个新的对象来替换 ---> shallowRef2. readOnly与shallowReadOnlyreadOnly:让一个响应式数据变为只读的(深只读)shallowReadOnly:让一个响应式数据变为只读的(浅只读)应用场景:不希望数据被修改时(如:使用的数据是别人传过来的)3. toRaw与markRawtoRow:作用:将一个由 reactive 生成的响应式对象转为普通对象使用场景:用于读取响应式对象对应的普通对象,对这个普通普通对象的所有操作,不会引起页面更新markRaw:作用:标记一个对象,使其永远不会成为响应式对象应用场景:有些值不应被设置为响应式的,如复杂的第三方类库当渲染的对象是不可变数据源的复杂/大列表时,跳过响应式转换可以提高性能4. customRef作用:自定义 ref ,并对其依赖项跟踪和更新触发进行显示控制实现防抖效果:<template> <br> <input type="text" v-model="keyWord"> <h3>{{keyWord}}</h3> </template> <script> import {customRef, ref} from "vue"; export default { name: 'MyDemo', setup() { //数据 //Vue提供的ref //let keyWord = ref('你好') function myRef(value, delay) { return customRef((track, trigger) => { let timer return { get() { console.log(`有人从自定义的myRef容器中读取了数据,value:[${value}]`) //通知Vue追踪value的变化 track() //2.读取 return value }, set(newValue) { console.log(`有人修改了自定义myRef容器中的数据,newValue:[${newValue}]`) clearTimeout(timer) timer = setTimeout(() => { //1.设置值 value = newValue //3.通知Vue重新解析模板 trigger() }, delay) } } }) } //使用自定义的ref let keyWord = myRef('你好', 500) return { keyWord } } } </script> <style scoped> </style>5. provide与inject作用:实现祖组件与后代组件间的通信实现:<!-- 祖组件 --> setup() { ...... let car = reactive({name: '马自达', price: '10w'}) //给后代组件传递数据 provide('car', car) ...... } <!-- 后代组件 --> setup() { ...... let car = inject('car') return {car} ...... }6. 响应式数据的判断isRef:检查是否是 ref 对象isReactive:检查是否是 reactive 对象isReadOnly:检查一个对象是否是由 readOnly 创建的只读代理对象isProxy:检查一个对象是否是由 reactive 或 readOnly 创建的代理对象
2022年07月17日
53 阅读
0 评论
0 点赞
2022-07-17
新的组件
1. FragmentVue2:组件必须有一个根标签Vue3:组件可以没有根标签,内部会将多个标签包含在一个 Fragment 虚拟元素中减少标签层间,性能优化2. Teleport概念:将 组件html结构 移动到指定位置<teleport to="body"> <div v-if="isShow" class="mask"> <div class="dialog"> <h3>你好</h3> <h4>孙笑川</h4> <h4>药水哥</h4> <h4>Giao哥</h4> <button @click="isShow = false">关闭弹窗</button> </div> </div> </teleport>3. Suspense等待异步组件时渲染定义的缺省内容,提升用户体验实现:引入异步组件import {defineAsyncComponent} from "vue"; const Child = defineAsyncComponent(() => import('./components/Child'))使用 Suspense 包裹组件,并配置好 default 和 fallback<template> <div class="app"> <h3>App组件</h3> <Suspense> <template v-slot:default> <Child/> </template> <template v-slot:fallback> <h3>加载中...</h3> </template> </Suspense> </div> </template>
2022年07月17日
20 阅读
0 评论
0 点赞
2022-07-17
常用Compsition API
1. setupVue3.0中一个新的配置项,值为一个函数,组件中所用到的数据、方法等均配置在setup中,有两种返回结果:(1)返回一个对象:则对象中的属性、方法可以直接在模板中使用(常用)(2)返回一个渲染函数:可以自定义渲染内容(3)注:setup 不能是一个 async 函数,因为返回值不再是 return 的对象,而是 Promise,模板看不到 return对象中的属性(后期可以是返回 Promise 实例,但需要 Suspense 和异步组件的配合)2. ref函数作用:定义一个响应式的数据语法:const xxx= ref(initValue)创建一个包含响应式数据的引用对象(reference对象,简称ref对象)在js中操作ref对象:xxx.value在模板中读取时不需要手动写.value,直接{{xxx}}补充:接收的数据可以是基本类型,也可以是对象类型基本类型数据:响应式依然通过 Object.defineProperty() 的 get 与set 完成对象类型的数据:内部求助Vue3.0的 reactive 函数来实现3. reactive函数作用:定义一个对象类型的响应式数据(基本类型使用ref)语法:const 代理对象 = reactive(源对象) 接收一个对象或数组,返回一个代理对象(即Proxy的实例对象,简称Proxy对象)reactive 定义的响应式数据是深层次的内部基于 ES6 的 Proxy 实现,通过代理对象操作源对象内部数据进行操作4. Vue3.0的响应式实现原理:通过Proxy(代理):拦截对象中任意属性的变化(增删查改)通过Reflect(反射):对源对象的属性进行操作Demo//源数据 let person = { name: '孙笑川', age: 33 } const p = new Proxy(person, { //读取时调用 get(target,propName) { console.log(`p身上的${propName}属性被读取了`) return Reflect.get(target, propName) }, //修改/追加时调用 set(target,propName,value) { console.log(`p身上的${propName}属性被修改了,执行页面更新`) Reflect.set(target, propName, value) }, //删除时调用 deleteProperty(target, propName) { console.log(`p身上的${propName}属性被删除了,执行页面更新`) return Reflect.deleteProperty(target, propName) } })5. reactive与ref的区别从定义数据的角度ref 定义基本数据类型reactive 定义对象或数组类型ref也可以定义对象或数组类型,底层会通过 reactive转为代理对象从原理的角度分析ref 通过 Object.defineProperty() 的 get 与 set 方法来实响应式(数据劫持)reactive 通过 Proxy 来实响应式(数据劫持),并通过 Reflect 操作源对象内部的数据从使用角度ref 定义的数据:操作数据时需要 .value,在模板中使用时不需要 .valuereactive 定义的数据:操作时直接使用即可6. setup的两个注意点setup执行的时机在 beforeCreate 之前执行一次,this 是 undefinedsetup的参数props:值为对象,包含组件外部传递过来,且组件内部声明接收了的属性context:上下文对象attrs:值为对象,包含组件外部传递过来,但没有在 props 配置中声明的属性,相当于 this.$attrsslots:收到的插槽内容,相当于 this.$slotsemit:分发自定义事件的函数,相当于 this.$emit7. computed函数与Vue2.x中一致示例:import {computed, reactive} from "vue"; export default { name: 'MyDemo', setup() { //数据 let person = reactive({ firstName: '孙', lastName: '笑川' }) //计算属性(简写) // person.fullName = computed(() => { // return person.firstName + '-' + person.lastName // }) //计算属性(完整写法) person.fullName = computed({ get() { return person.firstName + '-' + person.lastName }, set(value) { const nameArr = value.split('-') person.firstName = nameArr[0] person.lastName = nameArr[1] } }) return { person } } }8. watch函数与Vue2.x中一致注意:监视 reactive定义的响应式数据时,oldValue 无法正确获取,强制开启了深度监视(deep配置失效)监视 reactive定义的响应式数据中的某个属性(对象)时:deep 配置有效//情况一:监视ref定义的一个数据 watch(sum, (newValue, oldValue) => { console.log('sum变了',newValue, oldValue) }) //情况二:监视ref定义的多个数据 watch([sum, msg], (newValue, oldValue) => { console.log('sum变了', newValue, oldValue) }, {immediate:true}) /* 情况三:监视reactive定义的一个数据中的全部属性 注意:1.此处无法正确获取oldValue 2.强制开启了深度监视(deep配置无效) */ watch(person, (newValue, oldValue) => { console.log('person变了',newValue, oldValue) }, {deep: false}) //此处的deep配置无效 //情况四:监视reactive定义的一个数据中的某个属性 watch(() => person.name, (newValue, oldValue) => { console.log('person变了',newValue, oldValue) }) //情况五:监视reactive定义的一个数据中的某些属性 watch([() => person.name, () => person.age], (newValue, oldValue) => { console.log('person变了',newValue, oldValue) }) //特殊情况 watch(() => person.job, (newValue, oldValue) => { console.log('person变了',newValue, oldValue) }, {deep:true}) //此处由于监视的是reactive定义的对象中某个属性,所以deep配置有效9. watchEffect函数watch与watchEffect的区别:watch 既要指明监视的属性,也要指明监视的回调watchEffect 无需指明监视的属性,在监视的回调中用到哪个属性,那就监视哪个属性watchEffect与computed相似:computed 注重计算出来的值(回调函数的返回值),必须写返回值watchEffect 更注重过程(回调函数的函数体),不用写返回值//watchEffect所指定的回调中用到的数据只要发生变化,则直接重新执行回调 watchEffect(() => { const a = sum.value const b = person.job.j1.salary console.log('watchEffect配置的回调执行了') })10. 生命周期<script> import {onBeforeMount, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, onUpdated, ref} from "vue"; export default { name: 'MyDemo', setup() { //数据 let sum = ref(0) //通过组合式API的形式使用 onBeforeMount(() => { console.log('---onBeforeMount---') }) onMounted(() => { console.log('---onMounted---') }), onBeforeUpdate(() => { console.log('---onBeforeUpdate---') }), onUpdated(() => { console.log('---onUpdated---') }), onBeforeUnmount(() => { console.log('---onBeforeUnmount---') }), onUnmounted(() => { console.log('---onUnmounted---') }) return { sum } }, //通过配置项的形式使用生命周期钩子 /* beforeCreate() { console.log('---beforeCreate---') }, created() { console.log('---created---') }, beforeMount() { console.log('---beforeMount---') }, mounted() { console.log('---mounted---') }, beforeUpdate() { console.log('---beforeUpdate---') }, updated() { console.log('---updated---') }, beforeUnmount() { console.log('---beforeUnmount---') }, unmounted() { console.log('---unmounted---') } */ } </script>11. 自定义hook函数本质是一个函数,把 setup 中使用的Composition API进行了封装类似于Vue2.x中的mixin优势:代码复用,逻辑清晰12. toRef作用:创建一个 ref 对象,其 value 值指向一个对象中的某个属性语法:const name = toRef(person, 'name')应用:要将响应式对象中的某个属性单独提供给外部使用时扩展:toRef 与 toRefs 功能一致,但可以批量创建多个 ref 对象,语法:toRefs(person)
2022年07月17日
44 阅读
0 评论
0 点赞
2022-07-17
Router路由
概念:一个路由(route)就是一组映射关系(key - value,key为路径,value为组件),多个路由需要路由器(router)进行管理1. 基本使用(1)安装(以vue2为例):npm i vue-router@3(2)使用插件:Vue.use(VueRouter)(3)路由配置://路由配置 import VueRouter from 'vue-router' import About from '@/components/About' import Home from '@/components/Home' export default new VueRouter( { routes: [ { path: '/about', component: About }, { path: '/about', component: Home } ] })(3)路由切换:<router-link class="list-group-item" active-class="active" to="/about">About</router-link>(4)指定页面展示位置:<router-view></router-view>2. 几个注意点(1)路由组件一般放在views文件夹,一般组件放在components文件夹(2)通过切换,“隐藏”了的路由组件会被销毁,需要的时候再挂载;(3)每个路由组件都有自己的$route属性,存储对应的路由信息;(4)整个应用只有一个router3. 嵌套路由(1)使用children配置项:export default new VueRouter( { routes: [ { path: '/about', component: About }, { path: '/home', component: Home, children: [ { //子路由之前不写左斜杠“/” path: 'news', component: News }, { path: 'message', component: Message } ] } ] })(2)跳转(要写全路径)<router-link class="list-group-item" to="/home/news">News</router-link>4. 路由的query参数(1)传递参数<!-- 跳转路由并携带query参数,to的字符串写法 --> <router-link :to="`/home/message/detail?id=${m.id}&title=${m.title}`">{{m.title}}</router-link> <!-- 跳转路由并携带query参数,to的对象写法 --> <router-link :to="{ path: '/home/message/detail', query: { id: m.id, title: m.title } }"> {{m.title}} </router-link>(2)接收参数this.$route.query.id this.$route.query.title5. 命名路由(1)作用:简化路由的跳转(2)基本使用:命名{ path: '/home', component: Home, children: [ { //子路由之前不写左斜杠“/” path: 'news', component: News }, { path: 'message', component: Message, children: [ { name: 'detail', path: 'detail', component: Detail, } ] } ] }简化跳转<!-- 简化前 --> <router-link to="/home/message/detail">详情</router-link> <!-- 简化后,直接通过名字跳转 --> <router-link :to="{name:'detail'}">详情</router-link> <!-- 简化写法携带参数 --> <router-link :to="{ name: 'detail', query: { id: m.id, title: m.title } }">详情</router-link>6. 路由的params参数(1)配置路由,声明接收params参数{ path: '/home', component: Home, children: [ { //子路由之前不写左斜杠“/” path: 'news', component: News }, { path: 'message', component: Message, children: [ { name: 'detail', //使用占位符声明接收params参数 path: 'detail/:id/:title', component: Detail, } ] } ] }(2)传递参数(携带params时,必须使用路由名字,不能使用路径)<!-- 跳转路由并携带params参数,to的字符串写法 --> <!-- <router-link :to="`/home/message/detail/${m.id}/${m.title}`">详情</router-link> --> <!-- 跳转路由并携带params参数,to的对象写法 --> <router-link :to="{ name: 'detail', //携带params时,必须使用路由名字,不能使用路径 params: { id: m.id, title: m.title } }">详情</router-link>(3)接收参数this.$route.params.id this.$route.params.title7. 路由的props参数作用:方便路由组件接收参数{ path: 'message', component: Message, children: [ { name: 'detail', path: 'detail', component: Detail, //props的第一种写法,值为对象,该对象中的所有key-value都会以props的形式传给Detail组件 //props: {a:1,b:"B"} //props的第二种写法,值为布尔值,若值位真,就会把该路由组件收到的所有params参数,以props的形式传给Detail组件 //props: true //props的第三种写法,值为函数 /* props({$route}) { return { id: $route.query.id, title: $route.query.title, } } */ //简写 props({query:{id,title}}) { return { id,title } } } ] }8. <router-link>的replace属性(1)作用:控制路由跳转时操作浏览器历史记录的模式(2)浏览器历史记录有两种写入方式(默认为push):push:追加历史记录replace:替换当前记录(3)使用:<router-link replace></router-link>9. 编程式路由导航(1)作用:不借助<router-link>实现路由跳转(2)使用:<!-- push --> this.$router.push({ name: 'detail', query: { id: m.id, title: m.title } }) <!-- replace --> this.$router.replace({ name: 'detail', query: { id: m.id, title: m.title } }) <!-- 前进 --> this.$router.back() <!-- 后退 --> this.$router.forward() <!-- 前进/后退x步(x步长) --> this.$router.go(x)10. 缓存路由组件(1)作用:让不展示的路由组件保持挂载,不销毁(2)使用:<!--1.考虑要缓存的路由在哪个组件展示 2.include写的必须是组件名 3.缓存多个组件时使用双向绑定和数组形式即可,:inclue="['x','y']" --> <keep-alive include="MyNews"> <router-view></router-view> </keep-alive>11. 两个新的生命周期钩子(1)作用:路由组件所独有,用于捕获路由组件的激活状态(2)activated:路由组件激活时被触发 deactivated:反之,路由组件失活时被触发(3)标题淡化Demo://激活 activated() { console.log('News组件激活') this.timer = setInterval(() => { console.log('@') this.opacity -= 0.01 if (this.opacity <= 0) { this.opacity = 1 } }) }, //失活 deactivated() { console.log('News组件失活') clearInterval(this.timer) }12. 路由守卫(1)作用:对路由进行权限控制(2)分类:全局、独享、组件内守卫(3)全局守卫//全局前置路由守卫,初始化及每次路由切换之前被调用 router.beforeEach((to, from, next) => { console.log('前置路由守卫', to, from) //鉴权 if (to.meta.isAuth) { if (localStorage.getItem('token') === '1') { next() } else { alert('暂无查看权限!') } } else { next() } }) //全局后置路由守卫,初始化及每次路由切换之后被调用 router.afterEach((to, from) => { console.log('后置路由守卫', to, from) document.title = to.meta.title || 'Vue2 Demo' })(4)独享路由守卫beforeEnter(to,from,next) { console.log('独享路由守卫', to, from) //鉴权 if (to.meta.isAuth) { if (localStorage.getItem('token') === '1') { next() } else { alert('暂无查看权限!') } } else { next() } }(5)组件内守卫//通过路由规则,进入该组件时被调用 beforeRouteEnter(to, from, next) { console.log('About组件beforeRouteEnter', to, from) //鉴权 if (to.meta.isAuth) { if (localStorage.getItem('token') === '1') { next() } else { alert('暂无查看权限!') } } else { next() } }, //通过路由规则,离开该组件时被调用 beforeRouteLeave(to, from, next) { console.log('About组件beforeRouteLeave', to, from) next() }13. 路由器的两种工作模式(1)hash值:#号及其后面的内容(2)hash值不会包含在HTTP请求中,即hash值不会带给后台服务器(3)hash与history的区别:hash值地址栏会带着#号,兼容性好history模式地址干净美观,兼容性相较于hash略差,项目上线部署时需解决刷新404的问题
2022年07月17日
35 阅读
0 评论
0 点赞
2022-07-17
Vuex
1. 概念实现集中式状态(数据)管理的一个插件,对vue应用中多个组件的共享状态进行集中式的管理(读/写),也是一种组件间通信的方式(适用于任意组件间通信)2. 搭建vuex环境安装(以vue2为例):npm i vuex@3index.jsimport Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) //用于响应组件中的动作 const actions = { } //用于操作数据 const mutations = { } //用于存储数据 const state = { } //创建并暴露store export default new Vuex.Store({ actions,mutations,state })main.jsimport Vue from 'vue' import App from './App.vue' import store from './store' //关闭生产提示 Vue.config.productionTip =false new Vue({ el: '#app', render: h => h(App), store })3. 基本使用(1)配置actions,mutations,stateimport Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) //用于响应组件中的动作 const actions = { increment(context,value) { console.log('actions中的increment被调用') context.commit('INCREMENT', value) }, decrement(context,value) { context.commit('DECREMENT', value) }, incrementOdd(context,value) { if (context.state.sum % 2) { context.commit('INCREMENTODD', value) } }, incrementWait(context,value) { setTimeout(() => { context.commit('INCREMENTWAIT', value) }, 500) } } //用于操作数据 const mutations = { INCREMENT(state,value) { console.log('mutations中的INCREMENT被调用') state.sum += value }, DECREMENT(state,value) { state.sum -= value }, INCREMENTODD(state,value) { state.sum += value }, INCREMENTWAIT(state,value) { state.sum += value } } //用于存储数据 const state = { //当前的和 sum: 0, } //创建并暴露store export default new Vuex.Store({ actions,mutations,state })(2)组件中读取vuex中的数据:$store.state.sum(3)组件中修改vuex中的数据:$store.dispatch('方法名(小写)', 数据) 或 this.$store.commit('方法名(大写)', 数据) 注:若没有网络请求或其他业务逻辑,组件中可以跳过actions(即不写dispatch),直接(调用mutations)commit4. getters的使用(1)概念:当state中的数据需要经过加工后再使用时,可以使用getters(2)在store中追加getters配置//用于加工state中的数据 const getters = { bigSum(state) { return state.sum * 10 } } //创建并暴露store export default new Vuex.Store({ actions,mutations,state,getters })(3)组件中读取数据:$store.gettes.bigSum5. 四个map方法的使用(1)mapState(映射state中的属性为计算属性)//借助mapState生成计算属性,从state中读取数据 //对象写法 ...mapState({sum:'sum',school:'school',subject:'subject'}) //数组写法 ...mapState(['sum','school','subject']),(2)mapGetters(映射getters中的数据为计算属性)//借助mapGetters生成计算属性,从getter中读取数据 //对象写法 ...mapGetters({bigSum:'bigSum'}) //数组写法 ...mapGetters(['bigSum'])(3)mapMutations 用于帮助生成与mutations对话的方法,即:包含$store.commit(xxx)的函数//借助mapMutations生成对应的方法,方法中会调用commit去联系mutations //对象写法 ...mapMutations({increment:'INCREMENT',decrement:'DECREMENT'}), //数组写法 ...mapMutations(['INCREMENT','DECREMENT']),(4)mapActions 用于帮助生成与actions对话的方法,即:包含$store.dispatch(xxx)的函数//借助mapActions生成对应的方法,方法中会调用dispatch去联系actions //对象写法 ...mapActions({incrementOdd:'incrementOdd',incrementWait:'incrementWait'}), //数组写法 ...mapActions(['incrementOdd','incrementWait'])注:使用mapMutations与mapActions 时,若需要传递参数,需要在模板中绑定事件时就传递,否则默认的传参为时间对象6. 模块化、命名空间(1)目的:便于代码维护,数据分类更加明确(2)修改store/index.jsindex.jsimport Vue from 'vue' import Vuex from 'vuex' //求和相关 import countOptions from './count' //人员管理相关 import personOptions from './person' Vue.use(Vuex) //创建并暴露store export default new Vuex.Store({ modules: { countOptions, personOptions } })count.jsexport default { //开启命名空间 namespaced: true, actions: { ...... }, mutations: { ...... }, state: { ...... }, getters: { ...... }, }person.jsimport axios from "axios"; import {nanoid} from "nanoid"; export default { namespaced: true, actions: { ...... }, mutations: { ...... }, state: { ...... }, getters: { ...... }, }(3)开启命名空间后:组件读取state数据//方式一:直接读取 this.$store.state.personOptions.personList //方式二:借助map方法 ...mapState('personOptions', ['personList'])组件读取getters数据//方式一:直接读取 this.$store.getters['personOptions/firstPersonName'] //方式二:借助map方法 ...mapGetters('countOptions', ['bigSum'])组件调用dispatch方法//方式一:直接调用 this.$store.dispatch('personOptions/addPerson', personObj) //方式二:借助map方法 //参数在模板中绑定事件时就传递 ...mapActions('countOptions',['incrementOdd','incrementWait'])组件调用commit方法//方式一:直接调用 this.$store.commit('personOptions/ADD_PERSON', personObj) //方式二:借助map方法 //参数在模板中绑定事件时就传递 ...mapMutations('countOptions',{increment:'INCREMENT',decrement:'DECREMENT'}),
2022年07月17日
60 阅读
0 评论
0 点赞
2022-07-17
过度与动画
作用:再插入、更新或移除DOM元素时,在合适的时候给元素添加样式名语法:(1)准备样式元素进入的样式v-enter:进入的起点v-enter-active:进入过程中v-enter-to:进入的终点元素离开的样式v-leave:离开的起点v-leave-active:离开过程中v-leave-to:离开的终点(2)使用<transition>包裹要过度的元素,并配置name属性<transition name="demo"> <h1 v-show="isShow"> 孙笑川 </h1> </transition>(3)注:若有多个元素需要过度,则需要使用:<transition-group>,且每个元素都需要指定key值
2022年07月17日
44 阅读
0 评论
0 点赞
2022-07-17
配置代理
方式一在vue.config.js中添加如下配置:devServer: { proxy: 'http://localhost:5000' }注:(1)该方式配置简单,但不能配置多个代理,且不能灵活的控制请求是否走代理 (2)当请求了前端不存在的资源时,那么该请求会转发给服务器(优先匹配前端资源)方式二devServer: { proxy: { '/api': { target: 'http://localhost:5000', //路径重写 pathRewrite: {'^/api':''}, ws: true, //用于空值请求头中的host值(默认值为true) changeOrigin: true }, '/demo': { target: 'http://localhost:5001', pathRewrite: {'^/demo':''}, ws: true, changeOrigin: true } } }注:可以配置多个代理和灵活的控制请求是否走代理(请求时必须加上前缀)
2022年07月17日
26 阅读
0 评论
0 点赞
2022-07-17
全局事件总线(GlobalEventBus)
定义:一种组件间的通信方式,适用于任意组件间通信安装全局事件总线new Vue({ ...... beforeCreate() { //安装全局事件总线 Vue.prototype.$bus = this } })使用:(1)接收数据:A组件想接收数据,则在A组件中给$bus绑定自定义事件,且回调留在A组件自身methods: { demo(data) { ...... } } mounted() { this.$bus.$on('xxx', this.demo) }(2)提供数据:this.$bus.$emit('xxx', data)注:最好在beforeDestroy钩子函数中,使用$off('xxx')解绑当前组件所用到的自定义事件
2022年07月17日
43 阅读
0 评论
0 点赞
1
...
6
7
8
...
12