123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <div id="app">
- <!--
- 生命周期:
- 创建:
- beforeCreate 创建前:方法和数据是无法使用的
- created 创建后:方法和数据是可以使用的
- 运行:
- beforeMount 挂在前 虽然方法数据可以使用 但是真实页面未挂载
- mounted 挂在后 真实页面已经挂载
- beforeUpdate 更新前 值未改变
- updated 更新后 值已经改变
- 销毁:
- beforeDestroy 销毁前
- destroyed 销毁后
- -->
- <div id="first">{{msg}}</div>
- <button @click="change1">修改</button>
- </div>
- <script src="../vue初阶/vue.js"></script>
- <script>
- var vm = new Vue({
- el: "#app",
- data: {
- msg: "哈哈哈"
- },
- methods:{
- show() {
- console.log('ooo','ssss');
- },
- change1() {
- console.log('触发')
- this.msg = "嘿嘿嘿";
- }
- },
- beforeCreate() {
- console.log("创建前",this.msg);
- },
- created() {
- console.log("创建后",this.msg);
- },
- beforeMount() {
- console.log("挂载前",this.$el);
- this.show();
- },
- mounted() {
- console.log("挂载后",this.$el);
- },
- beforeUpdate() {
- console.log("更新前",this.$el,document.getElementById("first").innerHTML);
- },
- updated() {
- console.log("更新后",this.$el,document.getElementById("first").innerHTML);
- },
- beforeDestroy() {
- console.log("销毁前",document.getElementById("first").innerHTML,this.$el)
- },
- destroyed() {
- console.log("销毁后")
-
- },
- })
- </script>
- </body>
- </html>
|