vue官方文档提供的组件方式是:
Vue.component('my-component', {
code here
})
一些项目中的组件形式
<template lang="html">
</template>
<script>
export default{
}
</script>
<style lang="css">
</style>
这两种组件创建的方式有什么不一样吗?
vue官方文档提供的组件方式是:
Vue.component('my-component', {
code here
})
一些项目中的组件形式
<template lang="html">
</template>
<script>
export default{
}
</script>
<style lang="css">
</style>
这两种组件创建的方式有什么不一样吗?
13 回答12.8k 阅读
8 回答2.6k 阅读
2 回答5.1k 阅读✓ 已解决
7 回答1.9k 阅读
9 回答1.7k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
5 回答846 阅读
这是全局注册组件。
这是单文件组件,声明了一个组件的表现形式(实例),还没有完成注册,你可以把单文件组件里的代码当作Vue.component()的第二个参数里的东西。
使用的时候进行注册,可以使用
Vue.component('el-demo', Demo)
或者components: {Demo}
的形式进行注册。Vue.component()
全局注册,而按需加载,用哪个引哪个import Button from 'xxx', components: { Button }
就是另一种了。