使用 Vue.component 可以用来注册全局组件
// main.js ... import School from "./components/School.vue" Vue.component("test123", School) ...
// .vue <template> <div> ... // 组件无需引入,因为已经注册到全局了 <School></School> ... </div> </template> <script> export default { name:"Test" } </script>
可以进一步将其封装为一个插件,通过 Vue.use() 使用
// plugin.js import School from "@/components/School.vue" export default { install(Vue){ Vue.component("School", School) } }
标签:...,School,vue,封装,component,Vue,组件 From: https://www.cnblogs.com/xt112233/p/17005513.html