javascript
export default {
name: 'Test',
data () {
return {
test: 'testmsg'
}
},
components: {
},
methods:{
back() {
this.$router.push('/');
},
},
beforeCreate() {
// 此时获取不到data中的变量值
console.log(this.test)
},
beforeMount() {
console.log("beforeMount函数执行了----此时获取不到真实DOM");
console.log(document.getElementById("myDiv"));
},
created() {
console.log(this.test)
},
mounted() {
// mounted 挂载结束后可以获取到真实的DOM
console.log(document.getElementById("myDiv"));
}
}