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="../vue.js" 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="../vue.js" 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="../vue.js" 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="../vue.js" 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="../vue.js" 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
基础教程推荐
猜你喜欢
- 使用ajax跨域调用springboot框架的api传输文件 2023-02-23
- JS滚动到顶部踩坑解决记录 2023-07-10
- uniapp开发微信小程序自定义顶部导航栏功能实例 2022-10-21
- 关于Ajax跨域问题及解决方案详析 2023-02-23
- HTML clearfix清除浮动讲解 2022-11-20
- Javascript Bootstrap的网格系统,导航栏和轮播详解 2023-08-11
- cocos creator游戏实现loading加载页面,游戏启动加载动画 2022-10-29
- 在实战中可能碰到的几种ajax请求方法详解 2023-02-01
- Ajax+smarty技术实现无刷新分页 2022-12-15
- Ajax发送和接收请求 2022-12-15