当用vue-cli创建一个项目后,
创建项目的方法: https://www.cnblogs.com/fps2tao/p/9376847.html
编写了组件怎么,在其他组件中调用了?
组件listBox: 路径 src/components/listBox.vue
<template> <div class="listBox">listBox222</div> </template> <script> export default { name: "listBox", data:function(){ return {} } } </script> <style scoped> </style>
1.全局组件注册 复用
mian.js文件
import listBox from './components/listBox' //全局组件注册 Vue.component('listBox',listBox);
2.局部组件注册 复用
在要使用的组件中 引用 将要调用的组件
比如在App.vue中使用listBox 那么,App.vue下发如下:
<template> <div id="app"> <img src="./assets/logo.png"> <router-view/> <listBox></listBox> </div> </template> <script> import listBox from './components/listBox' export default { name: 'App', components:{ 'listBox':listBox } } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>