Vue.js组件之间的调用
index.html:运行完index.html之后自动寻找运行main.js文件main.js:import Vue from 'vue'import App from './App'import router from './router'Vue.config.productionTip = falsenew Vue({ el: '#app',
index.html:
<div id="app"></div>
运行完index.html之后自动寻找运行main.js文件
main.js:
import Vue from 'vue'
import App from './App'
import router from './router'
Vue.config.productionTip = false
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
然后进入app.vue
app.vue:
<template>
<div id="app">
<top></top>
<router-view></router-view>
<footerbottom>
</footerbottom>
</div>
</template>
<script>
import Top from './top'
import Footerbottom from './footerbottom'
export default {
name: 'app',
components: {
Top,
Footerbottom
}
}
</script>
根据标签的结构走,<top></top>放top.vue的内容
top.vue:
<template>
<h2>
top
</template>
<script>
export default({
name: 'top'
})
</script>
<footerbottom></footerbottom>放footerbottom.vue的内容
footerbottom.vue:
<template>
<h2>
bottom
</template>
<script>
export default({
name: 'footerbottom'
})
</script>
index.js:
import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/hello'
Vue.use(Router)
export default new Router({
routes: [
{ path: '/', component: Hello }
]
})
路由指向/components/hello.vue文件
hello.vue:
<template>
<p>
Hello world!
</template>
<script>
export default {
name: 'hello'
}
</script>
最后运行出来的效果如图:
更多推荐
所有评论(0)