Vue组件嵌套

全局注册

在main.js中注册组件Users

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false


import Users from './components/Users'
// 全局注册组件
Vue.component("users",Users)

/* eslint-disable no-new */
new Vue({
el: '#app',
components: { App },
template: "<App/>"
})

局部注册

在App.vue中注册

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<template>
<div id="app">
{{this.title}}
<users></users>
</div>
</template>

<script>
import Users from './components/Users';

export default {
name: 'App',
data(){
return {
title:"这是我的第一个vue程序"
}

},
// 这里不能使用 p div 等html元素名称
components:{"users":Users}
}
</script>

<style>

</style>

作者

Bruce Liu

发布于

2018-11-05

更新于

2022-11-12

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.