解释都在代码里,可以看看
<!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="../vue.js"></script>
</head>
<body>
<div id="app">
<hehe></hehe>
</div>
<template id="hehe">
<div class="test">
hehhe
<p ref='p'>{{num}}</p>
</div>
</template>
<script>
Vue.component('hehe',{
template:'#hehe',
data(){
return {
num:1
}
},
beforeCreate(){
console.log('创建之前');
console.log(this);
console.log(this.num);
console.log(this.$refs['p']);
},
created(){
console.log('创建结束');
console.log(this);
console.log(this.num);
this.num=5
console.log(this.$refs['p']);
}
})
let vm=new Vue({
el:'#app'
})
</script>
</body>
</html>
|