<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="app"> <h2>{{msg}}</h2> <h2>{{age}}</h2> </div> <button onclick="hadnleMount()">挂载</button> <button onclick="hadnleDestroy()">卸载</button> <button onclick="handleUpdate()">强制更新</button> </body> </html> <script src="./vue.js"></script> <script> var vm = new Vue({ data:{ msg:"1905" }, beforeMount(){ this.age = 20; } }) function hadnleMount(){ vm.$mount("#app");//手动挂载 } function hadnleDestroy(){ vm.$destroy(); //卸载 } function handleUpdate(){ vm.$forceUpdate() //如果属性身上没有setter/getter方法的时候可以进行强制更新 } /* vm.$mount: 手动挂载vue的作用范围 vm.$forceUpdate vm.$destroy vm.$nextTick */ </script>