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

教育培训机构排名seo是搜索引擎营销

教育培训机构排名,seo是搜索引擎营销,重庆seo排,wordpress 模板目录 一、基本使用1.1 watch配置监视1.2 vm.$watch动态监视1.3 深度监视(deep watch)1.4 简写形式 二、computed和watch的对比2.1 使用watch实现setTimeout操作2.2 用computed无法实现setTimeout 三、其他注意事项3.1 vue devtools的bug3.2 xxxyyy格式3.3 将window传入data中 V… 目录 一、基本使用1.1 watch配置监视1.2 vm.$watch动态监视1.3 深度监视(deep watch)1.4 简写形式 二、computed和watch的对比2.1 使用watch实现setTimeout操作2.2 用computed无法实现setTimeout 三、其他注意事项3.1 vue devtools的bug3.2 xxxyyy格式3.3 将window传入data中 Vue 提供了一种更通用的方式来观察和响应 Vue实例上的数据变动侦听属性也成为监视属性。 一、基本使用 监视属性watch: 当被监视的属性变化时回调函数handler自动调用进行相关操作。监视的属性必须存在才能进行监视。监视的两种写法 a. new Vue时传入watch配置 b. 通过vm.$watch来动态实现监视 1.1 watch配置监视 下面案例中我们通过watch配置属性来给isHuoguo 添加监视当isHuoguo发生变化时所配置的handler()函数会调用。 注意这里有一个属性immediate其默认值为false。当配置为true时页面初始化时让handler调用一下。 div idrooth2今天我们去吃{{info}}/h2button clickchange切换/button /div scriptconst vm new Vue({el:#root,data:{isHuoguo:true},computed:{info() {return this.isHuoguo?火锅:南京大排档;}},methods: {change() {this.isHuoguo !this.isHuoguo;}},watch: {isHuoguo:{immediate:true,//默认为false初始化时让handler调用一下。handler(newValue, oldValue) {console.log(isHuoguo属性被修改了newValuenewValueoldValueoldValue);}}}}) /script效果图如下 1.2 vm.$watch动态监视 不仅可以给属性即data中定义的添加监视也可以给计算属性添加监视。 下面例子我们通过vm.$watch 方式来动态给计算属性info添加监视 div idrooth2今天我们去吃{{info}}/h2button clickchange切换/button /div scriptconst vm new Vue({el:#root,data:{isHuoguo:true},computed:{info() {return this.isHuoguo?火锅:南京大排档;}},methods: {change() {this.isHuoguo !this.isHuoguo;}},watch: {isHuoguo:{// immediate:true,//默认为false初始化时让handler调用一下。handler(newValue, oldValue) {console.log(isHuoguo属性被修改了newValuenewValueoldValueoldValue);}}}})// 监视计算属性vm.$watch(info,{// immediate:true,//默认为false初始化时让handler调用一下。handler(newValue, oldValue) {console.log(info计算属性被修改了newValuenewValueoldValueoldValue);}})/script1.3 深度监视(deep watch) 深度监视(deep watch) Vue中的watch默认不监测对象内部值的改变只监测一层结构配置deep:true可以监测对象内部值的改变可以监测多层结构Vue默认不开启deep是为了提供效率。Vue自身可以监测对象内部值的改变但是Vue提供的watch默认不可以。使用watch时要根据数据的具体结构决定是否采用深度监视。 使用方式 监视多级结构中某个属性的变化例如下面例子中numbers.a监视多级结构中所有属性的变化numbers:{deep:true,handler(){}} div idrooth3今天我们去吃{{info}}/h3button clickchange切换/buttonhrh3a的值是{{numbers.a}}/h3button clicknumbers.a点击a/buttonhrh3b的值是{{numbers.b}}/h3button clicknumbers.b点击b/button /div scriptconst vm new Vue({el:#root,data:{isHuoguo:true,numbers:{a:1,b:1}},computed:{info() {return this.isHuoguo?火锅:南京大排档;}},methods: {change() {this.isHuoguo !this.isHuoguo;}},watch: {isHuoguo:{handler(newValue, oldValue) {console.log(isHuoguo属性被修改了newValuenewValueoldValueoldValue);}},// 监视多级结构中某个属性的变化numbers.a: {handler() {console.log(a被改变了);}},// 监视多级结构中所有属性的变化numbers:{deep:true,handler() {console.log(numbers改变了);}}}})/script1.4 简写形式 当所配置的监视只需要handler不需要其他配置的时候才可以使用简写形式使用函数来代替。 两类简写形式 watch配置里的简写动态添加监视的简写 div idrooth3今天我们去吃{{info}}/h3button clickchange切换/button /div scriptconst vm new Vue({el:#root,data:{isHuoguo:true},computed:{info() {return this.isHuoguo?火锅:南京大排档;}},methods: {change() {this.isHuoguo !this.isHuoguo;}},watch: {/* isHuoguo:{deep:true,immediate:true,handler(newValue, oldValue) {console.log(isHuoguo属性被修改了newValuenewValueoldValueoldValue);}}, */// 简写形式isHuoguo(newValue, oldValue) {console.log(isHuoguo属性被修改了newValuenewValueoldValueoldValue);}}})// 动态添加监视的简写vm.$watch(isHuoguo,function(newValue, oldValue){console.log(isHuoguo属性被修改了newValuenewValueoldValueoldValue);})/script二、computed和watch的对比 计算属性computed和监视属性watch之间的区别 computed能完成的功能watch都可以完成watch能完成的功能computed不一定能完成例如watch可以进行异步操作。 两个重要的原则 3. 被Vue所管理的函数最好写成普通函数这样this的指向才是vm或组件实例对象 4. 所有不被Vue管理的函数定时器的回调函数(setTimeout)、ajax的回调函数、Promise的回调函数等最好写成箭头函数这样this的指向才是 vm或 组件实例对象。 2.1 使用watch实现setTimeout操作 下面代码使用了watch实现setTimeout操作有一点需要注意的是setTimeout所指定的回调函数要使用箭头函数(因为箭头函数本身没有this)否则this指向window了而不再是vm实例。 div idrootdiv classrow姓input typetext v-modelfirstName/divdiv classrow名input typetext v-modellastName/divdiv classrow全名span{{fullName}}/span/div /divscriptconst vm new Vue({el:#root,data() {return {firstName: 小,lastName: 三,fullName:小-三};},methods:{},watch:{firstName(val) {setTimeout(() { //这里不能写成普通函数否则this指向window了console.log(this); //vm实例对象this.fullName val - this.lastName;}, 1000);},lastName(val){this.fullName this.firstName - val;}}}); /script2.2 用computed无法实现setTimeout 用computed计算属性无法实现setTimeout想要的功能如下错误代码所示 div idrootdiv classrow姓input typetext v-modelfirstName/divdiv classrow名input typetext v-modellastName/divdiv classrow全名span{{fullName}}/span/div/divscriptconst vm new Vue({el:#root,// 对于Vue来说data中配置的就是属性。// 计算属性用现有的属性去加工、计算生成一个全新的属性。和属性分开放data:{firstName: 小,lastName: 三},computed:{fullName() {console.log(get被调用了!);// console.log(this);setTimeout(() {return this.firstName-this.lastName}, 1000);}}}); /script三、其他注意事项 3.1 vue devtools的bug 当页面上没有用到某个计算属性时vue devtools调试工具会出现一个bug不会显示数据的变化了。例如下面代码 div idrooth2今天我们去吃米饭/h2button clickchange切换/button /div scriptconst vm new Vue({el:#root,data:{isHuoguo:true},computed:{info() {return this.isHuoguo?火锅:南京大排档;}},methods: {change() {this.isHuoguo !this.isHuoguo;}},}) /script点击切换按钮工具中显示的data和computed 不发生变化其实数据已经发生了改变。可以通过控制台中输入vm.info来查看。如下图所示 3.2 xxxyyy格式 这里的yyy不是事件名称而是一些简单的语句。例如clickisHuoguo !isHuoguo;count; 下面的案例中两个按钮均可实现功能。不过需要注意的是执行语句比较复杂的时候不建议直接写在yyy中。 div idrooth2今天我们去吃{{info}}--切换次数{{count}}/h2button clickchange切换/buttonbutton clickisHuoguo !isHuoguo;count切换2/button /div scriptconst vm new Vue({el:#root,data:{isHuoguo:true,count:0,},computed:{info() {return this.isHuoguo?火锅:南京大排档;}},methods: {change() {this.count;this.isHuoguo !this.isHuoguo;}},}) /script3.3 将window传入data中 将window传入data中实现alert弹框。如下代码所示 div idrooth2今天我们去吃{{info}}--切换次数{{count}}/h2button clickchange切换/buttonbutton clickisHuoguo !isHuoguo;count切换2/buttonbutton clickwindow.alert(1)弹出alert/button /div scriptconst vm new Vue({el:#root,data:{isHuoguo:true,count:0,window //相当于window:window},computed:{info() {return this.isHuoguo?火锅:南京大排档;}},methods: {change() {this.count;this.isHuoguo !this.isHuoguo;}},}) /script
http://www.pierceye.com/news/769937/

相关文章:

  • 网站备案简单吗优化关键词排名软件
  • 泉山网站开发安徽建设工程造价信息网
  • 如何使用电子商务网站做seo需要用到什么软件
  • 新乡商城网站建设哪家专业潮汕学院网站开发
  • 西安响应式网站开发网站空间多少钱一年
  • 做电子相册的大网站怎样提高网站的权重
  • seo网站设计外包去哪个网站有客户找做标书的
  • 微商招商网站源码互联网营销推广方案
  • 深圳做网站服务公司河北石家庄最新新闻
  • 山东济南seo整站优化唐山网站建设那家性价比高
  • c 可以做哪些网站小说网站建设采集
  • 公司网站备案条件高校网站集群平台子站开发
  • 制作网站能赚钱吗单位发购物或电影卡有哪些app
  • 我们网站在那里登陆后台系统管理网站建设服务咨询
  • 免费上传图片的网址网站seo工作内容
  • chatgpt 网站一对一直播软件开发
  • 网站做排行多少费用个人电脑做网站打不开数据库
  • 做网站是比特币的滁州做网站电话号码
  • php网站开发说明怎么样建网站卖东西
  • 网站图片做多大浙江建设人才网
  • 网站关键词宝塔wordpress腾讯云
  • 优化排名推广教程网站免费房地产网站模板
  • 商城网站建设都需要多少钱电子商务网站建设预算
  • 万荣做网站怎么优化一个网站关键词
  • 潍坊市建设局网站网络工程师 网站建设
  • 做网站要求什么条件计算机网络技术学什么
  • 建设网站呼叫中心有什么好处中国能源建设集团有限公司级别
  • 免费论坛建站二 网站建设的重要性
  • wordpress站点迁移怎样做带音乐的表白网站
  • 海淀网站制作网站建设基本技术