首页 > 编程 > JavaScript > 正文

使用watch监听路由变化和watch监听对象的实例

2019-11-19 14:18:47
字体:
来源:转载
供稿:网友

一、watch监听路由变化

解决办法:

export default{data(){return{}},watch:{"$route":"getPath" // 监听事件},methods:{getPath(){let path = this.$roune.path; //或得当前路径进行逻辑判断}}}

二、watch监听对象

例子:

<el-select v-model="form.region" placeholder="请选择">   <el-option     v-for="item in rootCategory" :key="item.id"     :label="item.name"     :value="item.id">   </el-option></el-select>export default{data(){return{ form:{ region:""}}},watch:{'form.region':function(newValue,oldValue){console.info(newValue);console.info(oldValue);}}}

以上这篇使用watch监听路由变化和watch监听对象的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表