在开发过程中,我们会把组件复用,以达到高效开发。当然,有的模块我们可以单独封装一个组件,防止代码冗余,也可以实现多次复用。
实现方法
- 引入组件 ,注册components。
<script>
//引入组件
import Sunny from "./Sunny"
export default {
name: 'HelloWorld',
//注册components
components:{Sunny},
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
2.直接在template里面使用引入的component的文件
<Sunny></Sunny>
以上即刻实现sunny组件在其他组件的复用!