61 lines
1.5 KiB
HTML
61 lines
1.5 KiB
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>vue生命周期</title>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="app">
|
|
<h2 ref="test">{{ test }}</h2>
|
|
</div>
|
|
|
|
</body>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
|
|
<script>
|
|
// TODO activated 需要说明
|
|
var vm = new Vue({
|
|
el: '.app',
|
|
data: {
|
|
test: '你好'
|
|
},
|
|
// 发送ajax请求
|
|
created() {
|
|
console.log(this.$refs.test);
|
|
// console.log(document.querySelector("h2"));
|
|
},
|
|
// 也可以发送ajax请求
|
|
mounted() {
|
|
this.getTest
|
|
console.log(this.getHello);
|
|
console.log(this.$refs.test);
|
|
},
|
|
updated() {
|
|
console.log("数据更新了");
|
|
},
|
|
methods: {
|
|
getTest() {
|
|
console.log("getTest");
|
|
}
|
|
},
|
|
|
|
// computed 写法上和 methods 是一样的,
|
|
// 会做缓存
|
|
computed: {
|
|
getHello() {
|
|
console.log("getHello");
|
|
return 1
|
|
}
|
|
},
|
|
// 使用watch 监听数据的修改,触发一些其他操作
|
|
watch: {
|
|
test(newVal, oldVal) {
|
|
console.log("newVal: ", newVal);
|
|
console.log("oldVal: ", oldVal);
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</html> |