mileOfSunshine / blog

2 stars 0 forks source link

Vue #5

Open mileOfSunshine opened 5 years ago

mileOfSunshine commented 5 years ago
mileOfSunshine commented 5 years ago

tools

mileOfSunshine commented 3 years ago

Vue中import from的来源:省略后缀与加载文件夹

mileOfSunshine commented 2 years ago

Vue data 中随意更改一个属性,视图都会被更新吗?

不会。如果该属性没有被用到 template 中,就没有必要去更新视图,频繁这样性能不好。 在实例初始化过程中,利用 Object.defineProperty 对 data 中的属性进行数据监听,如果在 template 中被使用到的属性,就被 Dep 类收集起来,等到属性被更改时会调用 notify 更新视图。

如何知道哪些属性是在 template 被用到的? template 会被编译成 render 函数,函数执行的时候,访问什么变量,就出触发相应变量的 get,然后才会添加 watcher

mileOfSunshine commented 1 year ago

vscode 快速生成 vue 模板

  1. 用快捷Ctrl + Shift + P唤出控制台
  2. 然后输入“snippets”并选择
  3. 接着输入vue
  4. 配置 vue.json 文件如下:
{

    "Print to console": {
        "prefix": "vue",
        "body": [
            "<template>",
            "  <div></div>",
            "</template>",
            "",
            "<script>",
            "export default {",
            "  name: \"$0\",",
            "  components: {},",
            "  props: {},",
            "  data() {",
            "    return {",
            "    };",
            "  },",
            "  watch: {},",
            "  computed: {},",
            "  methods: {},",
            "  created() {},",
            "  mounted() {}",
            "};",
            "</script>",
            "<style lang=\"scss\" scoped>",
            "</style>"
        ],
        "description": "A vue file template"
    }
}
  1. 然后新建一个 vue 文件,输入“vue”,按下回车键或者Tab键,模板就自动生成了:

image

mileOfSunshine commented 1 year ago

通过cdn形式引入的UI库,会在其注入在window上。

例如: