Vue 组件之间的引入

7 篇文章 0 订阅
本文介绍了如何在Vue应用中进行组件之间的引入和通信。通过示例展示了在index.html中设置路由指向hello.vue组件,以及hello.vue组件的实现细节。最终运行结果呈现出Vue组件的交互效果。
摘要由CSDN通过智能技术生成

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.vue的内容
top.vue:

<template>

<h2>

top
</h2>

</template>
<script>
export default({
  name: 'top'
})
</script>
放footerbottom.vue的内容 footerbottom.vue:
<template>

<h2>

bottom
</h2>

</template>
<script>
export default({
  name: 'footerbottom'
})
</script>
默认指向router文件夹下的index.js文件,
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!
</p>

</template>
<script>
export default {
  name: 'hello'
}
</script>

最后运行出来的效果如图:

转载自:http://blog.csdn.net/web_xiaolei/article/details/68943074
(感谢这篇文章在我接触Vue时遇到的问题遇到)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值