vue.js

关注公众号 jb51net

关闭
首页 > 网络编程 > JavaScript > javascript类库 > vue.js > vue 加载解析顺序

vue 组件数据加载解析顺序的详细代码

作者:英俊潇洒美少年

Vue.js的解析顺序可以概括为:模板编译、组件创建、数据渲染、事件处理和生命周期钩子函数执行,接下来通过本文给大家介绍vue 组件数据加载解析顺序的完整代码,感兴趣的朋友跟随小编一起看看吧

组件数据加载解析顺序

实例初始化完成、props 解析 -> beforeCreate -> 响应式数据、计算属性、方法和侦听器设置完成 -> created -> 判断是否有渲染模版 -> beforeMount -> 组件挂载 -> mounted

import Vue from "vue";
new Vue({
  el: "#app",
  template: `<div>
    <div>{{computedCount}}</div>
  </div>`,
  data() {
    return {
      count: 1,
    }
  },
  watch: {
    count: {
      handler() {
        console.log('watch');
      },
      immediate: true,
    }
  },
  computed: {
    computedCount() {
      console.log('computed');
      return this.count + 1;
    }
  },
  created() {
    console.log('created');
  },
  mounted() {
    console.log('mounted');
  },
});
watch -> created -> computed -> mounted
new Vue({
  el: "#app",
  template: `<div>
    <div></div>
  </div>`,
  data() {
    return {
      count: 1,
    }
  },
  watch: {
    count: {
      handler() {
        console.log('watch');
      },
      immediate: true,
    }
  },
  computed: {
    computedCount() {
      console.log('computed');
      return this.count + 1;
    }
  },
  created() {
    console.log('created');
  },
  mounted() {
    console.log('mounted');
  },
});
watch -> created -> mounted
new Vue({
  el: "#app",
  template: `<div>
    <div></div>
  </div>`,
  data() {
    return {
      count: 1,
    }
  },
  watch: {
    count: {
      handler() {
        console.log('watch');
      },
      immediate: true,
    }
  },
  computed: {
    computedCount() {
      console.log('computed');
      return this.count + 1;
    }
  },
  created() {
    console.log('created');
  },
  mounted() {
    console.log('mounted');
    this.computedCount
  },
});
watch -> created -> mounted -> computed

到此这篇关于vue 组件数据加载解析顺序的文章就介绍到这了,更多相关vue 组件数据加载内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文