Vue.component的问题,帮忙解答一下~

Vue.component(name,obj);
我看vue官网上市这样写的
Vue.component('my-component', {
template: '<div>A custom component!</div>'
})
注册一个全局的模板,<my-component><my-component>

能不能不直接在template写代码,
而是引用写好的.vue文件。做my-component的template??? 能的话 要怎么写???

阅读 2.1k
1 个回答

1.官网上的代码使用于前端非工程化开发中,比较简单的模式

2.进阶的话,也就是使用vue文件,进行编译咯哟。更多参考vue-cli 生成的 template

import Hello from "./hello.vue";

hello.vue

<template>
<div></div>
</template>
<script></script>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题