1.Vue实例变量vm app 一般都代表vue实例 el:负责定义Vue定义的接管的dom最外层标签2.生命周期函数生命周期函数就是Vue实例在某一个时间点会自动执行的函数。(1)beforeCreate!DOCTYPE htmlhtmlheadmet...
1.Vue实例
变量vm app 一般都代表vue实例
el:负责定义Vue定义的接管的dom最外层标签
2.生命周期函数
生命周期函数就是Vue实例在某一个时间点会自动执行的函数。
(1)beforeCreate
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="Li4vdnVlLmpz" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
Hello World
</div>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
beforeCreate:function(){
console.log("beforeCreate")
}
})
</script>
</body>
</html>
(2).created
(3).beforeMount
模板和数据相结合即将挂载到页面上之前执行。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="Li4vdnVlLmpz" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
Hello World
</div>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
template:"<div>Hello World</div>",
beforeCreate:function(){
console.log("beforeCreate")
},
created:function(){
console.log("created")
},
beforeMount:function(){
console.log("beforeMount")
}
})
</script>
</body>
</html>
(4).mounted
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="Li4vdnVlLmpz" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
Hello World
</div>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
template:"<div>Hello World</div>",
beforeCreate:function(){
console.log("beforeCreate")
},
created:function(){
console.log("created")
},
beforeMount:function(){
console.log("beforeMount")
},
mounted:function(){
console.log("mounted")
}
})
</script>
</body>
</html>
(5).beforeDestroy与destroyed
vm.$destroy()可以消除vm组件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="Li4vdnVlLmpz" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
Hello World
</div>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
template:"<div>Hello World</div>",
beforeCreate:function(){
console.log("beforeCreate")
},
created:function(){
console.log("created")
},
beforeMount:function(){
console.log("beforeMount")
},
mounted:function(){
console.log("mounted")
},
beforeDestroy:function(){
console.log("beforeDestroy")
},
destroyed:function(){
console.log("destroyed")
}
})
</script>
</body>
</html>
(6).beforeUpdate与updated
vm.text=“text”//修改text里面的内容
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="Li4vdnVlLmpz" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
Hello World
</div>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
template:"<div>{{text}}</div>",
data:{
text:"hello world"
},
beforeCreate:function(){
console.log("beforeCreate")
},
created:function(){
console.log("created")
},
beforeMount:function(){
console.log("beforeMount")
},
mounted:function(){
console.log("mounted")
},
beforeDestroy:function(){
console.log("beforeDestroy")
},
destroyed:function(){
console.log("destroyed")
},
beforeUpdate:function(){
console.log("beforeUpdate")
},
updated:function(){
console.log("updated")
}
})
</script>
</body>
</html>
沃梦达教程
本文标题为:Vue入门笔记Day4


猜你喜欢
- JS实现左侧菜单工具栏 2022-08-31
- vue keep-alive 2023-10-08
- layui数据表格以及传数据方式 2022-12-13
- 基于CORS实现WebApi Ajax 跨域请求解决方法 2023-02-14
- 关于 html:如何从 css 表中删除边距和填充 2022-09-21
- jsPlumb+vue创建字段映射关系 2023-10-08
- 深入浅析AjaxFileUpload实现单个文件的 Ajax 文件上传库 2022-12-15
- 1 Vue - 简介 2023-10-08
- javascript 判断当前浏览器版本并判断ie版本 2023-08-08
- ajax实现输入提示效果 2023-02-14