Vue组件的创建和引用。

Vue组件的创建和引用。

1、VSCode 安装了Vue VSCode Snippets的插件。方便代码编写时快速生成。
2、用Vue CLI ,创建项目,只创建基本配置,方便测试学习。
3、新建Parent.vue文件,键入 vbase ,快速生成组件需要的标签。

<template>
    <div>

    </div>
</template>

<script>
    export default {

    }
</script>

<style >

</style>

4、在APP.vue中引入Parent组件,方法分3步:1、在script中引入。2、在script中注册组件。3、在template中使用组件。

<template>
  <div id="app">
    <m-parent></m-parent>  //3、使用
  </div>
</template>

<script>
  import MParent from './views/Parent.vue' //1、引入
  export default {
    components: {          //2、注册
      MParent
    }
  }
</script>

<style>
</style>

猜你喜欢

转载自blog.51cto.com/133146/2490920