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

电商网站建设课程网络服务提供者

电商网站建设课程,网络服务提供者,苏州北京网站建设,快手秒刷自助网站目录 一、引出生命周期 二、生命周期_挂载流程 三、生命周期_更新流程 四、生命周期_销毁流程 五、生命周期_总结 一、引出生命周期 生命周期: 1.又名:生命周期回调函数、生命周期函数、生命周期钩子。 2.是什么:Vue在关键时刻帮我们调…

目录

一、引出生命周期

二、生命周期_挂载流程

三、生命周期_更新流程

四、生命周期_销毁流程

五、生命周期_总结

一、引出生命周期

生命周期:

    1.又名:生命周期回调函数、生命周期函数、生命周期钩子。

    2.是什么:Vue在关键时刻帮我们调用的一些特殊名称的函数

    3.生命周期函数的名字不可更改,但函数的具体内容是程序员根据需求编写的。

    4.生命周期函数中的this 指向vm组件实例对象

Vue完成模板的解析并把初始的真实的DOM元素放入页面后(挂载完毕)调用mounted

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>document</title><script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>	
</head>
<body>	<div id="root"><h2 v-if="a">你好啊</h2><!-- {opacity}为{opacity: opacity}的简写形式,第一个opacity为属性,第二个为属性值 --><h2 :style="{opacity}">欢迎学习Vue</h2><!-- {{change()}} --></div><script type="text/javascript">	Vue.config.productionTip = falseconst vm = new Vue({el:'#root',data:{opacity:1,a:false,},methods:{/* change(){setInterval(()=>{this.opacity -= 0.01if(this.opacity <= 0) this.opacity = 1},16)}, */},// Vue完成模板的解析并把初始的真实的DOM元素放入页面后(挂载完毕)调用mountedmounted() {console.log('mounted',this);//此处的this是vue实例setInterval(()=>{vm.opacity -= 0.01if(vm.opacity <= 0) vm.opacity = 1},16)},			})// 通过外部的定时器实现(不推荐)/* setInterval(()=>{vm.opacity -= 0.01if(vm.opacity <= 0) vm.opacity = 1},16) */</script>
</body>
</html>

二、生命周期_挂载流程

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="./js/vue.js"></script></head>
<body><!-- 准备好一个容器 --><div id="root"><h2 v-if="false">你好啊</h2><h2 :style="{opacity}">欢迎学习 Vue</h2><h2>当前的n值是:{{n}}</h2><button @click="add">点我 n+1</button></div><script type="text/javascript">const vm = new Vue({el: '#root',// template: ` //     <div>//         <h2>当前的n值是:{{n}}</h2>//         <button @click="add">点我 n+1</button>//     </div>// `,data: {opacity:1,n: 1},methods: {add(){this.n++}},beforeCreate() {console.log('beforeCreate')// console.log(this);// debugger},created() {console.log('created')// console.log(this);// debugger},beforeMount() {console.log('beforeMount')// console.log(this);// debugger               },mounted(){console.log('mounted')// console.log(this);// debugger   /* setInterval(() => {this.opacity -= 0.01if (this.opacity < 0) {this.opacity = 1}}, 16) */}})    </script>
</body>
</html>

三、生命周期_更新流程

在哪个生命周期 钩子中页面与数据尚未不同步: beforeUpdate

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="./js/vue.js"></script></head>
<body><!-- 准备好一个容器 --><div id="root"><h2 v-if="false">你好啊</h2><h2 :style="{opacity}">欢迎学习 Vue</h2><h2>当前的n值是:{{n}}</h2><button @click="add">点我 n+1</button></div><script type="text/javascript">const vm = new Vue({el: '#root',// template: ` //     <div>//         <h2>当前的n值是:{{n}}</h2>//         <button @click="add">点我 n+1</button>//     </div>// `,data: {opacity:1,n: 1},methods: {add(){this.n++}},beforeCreate() {console.log('beforeCreate')// console.log(this);// debugger},created() {console.log('created')// console.log(this);// debugger},beforeMount() {console.log('beforeMount')// console.log(this);// debugger               },mounted(){console.log('mounted',this.$el,this.$el instanceof HTMLElement)// console.log(this);// debugger   /* setInterval(() => {this.opacity -= 0.01if (this.opacity < 0) {this.opacity = 1}}, 16) */},beforeUpdate() {console.log('beforeUpdate')// console.log(this.n);  //点击按钮 此时已变成 2// debugger},updated() {console.log('updated')debugger},})    </script>
</body>
</html>

四、生命周期_销毁流程

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="./js/vue.js"></script></head>
<body><!-- 准备好一个容器 --><div id="root"><h2 v-if="false">你好啊</h2><h2 :style="{opacity}">欢迎学习 Vue</h2><h2>当前的n值是:{{n}}</h2><button @click="add">点我 n+1</button><button @click="bye">点我销毁vm</button></div><script type="text/javascript">const vm = new Vue({el: '#root',// template: ` //     <div>//         <h2>当前的n值是:{{n}}</h2>//         <button @click="add">点我 n+1</button>//     </div>// `,data: {opacity:1,n: 1},methods: {add(){console.log('add');this.n++},bye(){console.log('bye');this.$destroy()}},beforeCreate() {console.log('beforeCreate')// console.log(this);// debugger},created() {console.log('created')// console.log(this);// debugger},beforeMount() {console.log('beforeMount')// console.log(this);// debugger               },mounted(){console.log('mounted',this.$el,this.$el instanceof HTMLElement)// console.log(this);// debugger   /* setInterval(() => {this.opacity -= 0.01if (this.opacity < 0) {this.opacity = 1}}, 16) */},beforeUpdate() {console.log('beforeUpdate')// console.log(this.n);  //点击按钮 此时已变成 2// debugger},updated() {console.log('updated')// debugger},beforeDestroy() {console.log('beforeDestroy')console.log(this.n)this.add()  //仍可使用 add,但对数据触发的操作不再更新,所以页面中 的n不会改变},destroyed() {console.log('destroyed')},})         </script>
</body>
</html>

五、生命周期_总结

上面一共讲了8 个生命周期,也就是4 对生命周期

beforeCreate 与 created  指数据检测与数据代理创建之前和之后

beforeMount 与 Mounted  

beforeUpdate 与 updated

beforeDestroy 与 destroy 

常用的生命周期钩子:
     1.mounted: 发送ajax请求、启动定时器、绑定自定义事件、订阅消息等【初始化操作】。
     2.beforeDestroy: 清除定时器、解绑自定义事件、取消订阅消息等【收尾工作】。

 关于销毁Vue实例
     1.  销毁后借助Vue开发者工具看不到任何信息。
     2.  销毁后自定义事件会失效,但原生DOM事件依然有效。

     3.  一般不会在beforeDestroy 操作数据,因为即便操作数据,也不会再触发更新流程了。

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="./js/vue.js"></script></head>
<body><!-- 准备好一个容器 --><div id="root"><!-- 需求:点击按钮停止变换 --><h2 :style="{opacity}">欢迎学习 Vue</h2><button @click="opacity = 1">透明度设置为1</button><button @click="stop">停止变换</button></div><script type="text/javascript">const vm = new Vue({el: '#root',data: {opacity:1,},methods: {stop(){this.$destroy()}},mounted(){  this.timer = setInterval(() => {this.opacity -= 0.01console.log('定时器');if (this.opacity < 0) {this.opacity = 1}}, 16)},beforeDestroy() {console.log();clearInterval(this.timer)},           })         </script>
</body>
</html>

http://www.mnyf.cn/news/45327.html

相关文章:

  • 做网站分辨率多少钱某网站seo诊断分析
  • 安徽建站优化哪里有镇江交叉口优化
  • 专业做网站公司 前景全球搜钻
  • 免费推广企业网站常用的网络营销方法及效果
  • 重庆网站改版青岛谷歌推广
  • wordpress文章页图片seo推广技巧
  • 怎么用自己的网站做邮箱网络推广图片
  • 网站建设nayuwangseo优化费用
  • 网站开发计入管理费用哪个明细郑州seo技术代理
  • 怎么自己建设一个网站企业微信scrm
  • 网站标题title怎么写互联网舆情信息
  • 网站建设公司哪家好速找盛世传媒打开2345网址大全
  • 在自己网站做blog培训机构咨询
  • 做充气气模产品一般去哪些网站网站服务器地址查询
  • 沧州网站建设报价推销广告
  • 公司网站404石家庄seo代理商
  • 辅导班如何做网站网站建设运营
  • 企业网站建设的背景和目的百度平台客服人工电话
  • 做网站税率现在感染症状有哪些
  • 个人备案的网站做企业站室内设计培训哪个机构比较好
  • 自建网站做淘宝联盟百度地图导航手机版免费下载
  • 广东住房和建设局网站培训网站排名
  • 龙岩网站设计理念桔子seo网
  • wordpress模版如何汉化google seo 优化教程
  • 设计师的个人网站贵州萝岗seo整站优化
  • 免费推广原因优化方案官网
  • wordpress v3.3.1空间上传phpseo怎么刷关键词排名
  • 找网络公司做网站需要注意成品视频直播软件推荐哪个好用
  • 如何提升网站的转化率广告联盟怎么加入
  • 做软件推广网站怎么赚钱多合一seo插件破解版