vue3 可以写多个watch
import { reactive,toRefs,computed,watch } from 'vue'; import { useStore } from
'vuex'; export default { setup(){ //定义vuex方法 const store = useStore(); //初始化
相当于vue2的data const state = reactive({ //使用计算属性动态拿到vuex的值 radioVal: computed(()
=> { return store.state.headerObj.radioVal; }), radioIndex: computed(() => {
return store.state.headerObj.radioIndex }), }) //watch监听动态拿到值的变化,从而做出反应 watch(()
=> state.radioVal,(newVal,oldVal)=>{ console.log(newVal) console.log(oldVal) }
//如果想监听多个值,在多写几个watch watch(()=> state.radioIndex,(newVal,oldVal)=>{ console.log
(newVal,oldVal,'测试') }) return{ ...toRefs(state), } }, }

技术
今日推荐
PPT
阅读数 121
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信