TOP

PeterChu PeterChu

我的自留地

目录
浅尝 Vue —— 笔记一 component 组件创建方式
/        

浅尝 Vue —— 笔记一 component 组件创建方式

component 组件创建方式

1. component 组件创建方式一

const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
引用:
const routes = [
  { path: '/foo', component: Foo },
  { path: '/bar', component: Bar }
]

2. component 组件创建方式二

创建 .vue 文件,
router/index.jsimport Demo from '../components/Demo.vue'

然后在 routes 的数组对象中直接使用, eg:

{
  path: '/demo-vue',
  name: 'DemoVue',
  component: DemoVue
},

3. component 组件创建方式三

创建 .vue 文件,
然后直接在 routes 的数组对象中直接使用, eg:

{
  path: '/demo-vue',
  name: 'DemoVue',
  component: () => import('../views/demo-vue.vue')
},

第三种方式是与第二种方式同质。


标题:浅尝 Vue —— 笔记一 component 组件创建方式
作者:PeterChu
地址:https://txjchu.gitee.io/articles/2021/02/10/1612937674709.html