12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <!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>
- </head>
- <body>
- <div id="app">
- <button @click="fn()">+1</button>
- <button @click=des()>销毁</button>
- <h2 id="myCount">{{count}}</h2>
- </div>
- <script src="vue.js"></script>
- <script>
- new Vue({
- el:"#app",
- data:{
- count: 1
- },
- methods:{
- fn(){
- this.count++
- },
- des(){
- this.$destroy()
- }
- },
- //组件实例刚刚创建的时候 属性计算之前
- beforeCreate(){
- console.log('beforeCreate',this.$data,this.$el)
- },
- //组件实例刚刚创建完成 属性绑定上了 但是 dom未生成 所以el不存在
- created(){
- console.log('created',this.$data,this.$el)
- },
- //挂载之前
- beforeMount(){
- console.log('beforeMount',this.$data,this.$el)
- },
- //挂载之后
- mounted(){
- console.log('mounted',this.$data,this.$el)
- },
- beforeUpdate(){
- console.log('beforeUpdate',document.getElementById('myCount').innerHTML)
- },
- updated(){
- console.log('updated',document.getElementById('myCount').innerHTML)
- },
- beforeDestroy(){
- console.log('beforeDestroy')
- },
- destroyed(){
- console.log('destroyed')
- }
- })
- </script>
- </body>
- </html>
|