太仓市住房和城乡建设局官方网站,东莞外贸网站建设策划方案,做网站还是小程序,哈尔滨网站建设招聘component组件解析
component组件的写法在众多组件写法中算是比较简单的#xff0c;component组件结构组成如下#xff1a;
1#xff09;组件名 2#xff09;组件模板 3#xff09;利用Vue对象进行生成
基础示例#xff1a; div idapptestcomponent组件结构组成如下
1组件名 2组件模板 3利用Vue对象进行生成
基础示例 div idapptest/test/divscriptVue.component(test, {template: h1这是一个组件模板/h1})new Vue({el:#app})/script component组件
我们可以通过在实例外部以component的方式拓展单个组件当前方式需要在构建全局实例之前进行组件创建不存在组件提升。类似于变量提升
1创建组件 div idapptest/test/divscriptVue.component(test, {template: h1这是一个组件模板/h1})new Vue({el:#app})/script 2分离模板创建组件 div idapptest/test/divscriptlet tem {template: h1这是一个组件模板/h1}Vue.component(test, tem);new Vue({el:#app})/script 3通过components拓展组件
components和methods类似表示组件集合我们也可以直接通过components进行组件拓展 div idapptest/test/divscriptnew Vue({el:#app,components: {test: {template: h1这是一个组件模板/h1}}})/script 驼峰式命名
驼峰式命名在使用的时候需要将调用的组件名转换成横杠式 div idapptest-me/test-me/divscriptVue.component(testMe, {template: h1这是一个组件模板/h1})new Vue({el:#app})/script 组件中的DOM包裹规则
1单DOM组件 div idapptest/test/divscriptVue.component(test, {template: h1这是一个组件模板/h1})new Vue({el:#app})/script 2多DOM组件
如果组件涉及的DOM较多必须要将所有DOM包裹在一个主DOM中否则将报错 div idapptest/test/divscriptVue.component(test, {template: divh1这是一个组件模板/h1h1这是第二个组件模板/h1/div})new Vue({el:#app})/script 3配合ES6模板语法使用 div idapptest/test/divscriptVue.component(test, {template: divh1这是一个组件模板/h1h1这是第二个组件模板/h1/div})new Vue({el:#app})/script