liangxiaojuan / eleme

restructure..
1.6k stars 564 forks source link

有个关于vue-router的问题想请教一下 #11

Closed siogo closed 5 years ago

siogo commented 7 years ago

就是我在使用了vue-router之后,页面上挂载不出来我的app这个组件 这是我的app.vue页面 ``

这是main.js `import Vue from 'vue'; import VueRouter from 'vue-router'; import App from './App'; import goods from './components/goods/goods';

Vue.use(VueRouter);

let routes = [ {path:'/goods',component: goods} ]

let router = new VueRouter({ routes })

let app = new Vue({ router }).$mount('#app')

`

这是index.html `<!DOCTYPE html>

sell
` 麻烦告知一下要怎么弄才能挂载上去
liangxiaojuan commented 7 years ago

let routes = [ {path:'/',component: App} {path:'/goods',component: goods}, ] 你要把 app 这个组件用上才行啊

siogo commented 7 years ago

谢谢你

Get Outlook for iOShttps://aka.ms/o0ukef


From: Yangyi notifications@github.com Sent: Friday, February 24, 2017 9:47:06 AM To: liangxiaojuan/eleme Cc: siogo; Author Subject: Re: [liangxiaojuan/eleme] 有个关于vue-router的问题想请教一下 (#11)

let routes = [ {path:'/',component: App} {path:'/goods',component: goods}, ] 你要把 app 这个组件用上才行啊

― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/liangxiaojuan/eleme/issues/11#issuecomment-282179499, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIyHxZinV3bR4qhiVkEC0MjyLwJc4y5mks5rfjaagaJpZM4MJ9p7.

chendayang commented 7 years ago

@siogo @liangxiaojuan 我碰到同样的问题了,我加载app组件了,但是页面是空白的,div#app内部是空的

main.js文件: `import Vue from 'vue' import VueRouter from 'vue-router' import App from './App' import goods from 'components/goods/goods.vue' import seller from 'components/seller/seller.vue' import ratings from 'components/ratings/ratings.vue' Vue.config.productionTip = false

Vue.use(VueRouter) let routes = [ {path: '/', component: App}, {path: '/goods', component: goods}, {path: '/ratings', component: ratings}, {path: '/seller', component: seller} ] let router = new VueRouter({ routes }) let app = new Vue({ router }) app.$mount('#app')`

Ale-cc commented 7 years ago

@siogo @chendayang 少了export default app;没有导出组件,自然加载不到。 可以换一种更加简洁的写法 ` import Vue from 'vue' import Router from 'vue-router'

Vue.use(Router)

import Hello from 'components/Hello' import Types from 'components/Types' import TabContainer from 'components/TabContainer' import Picker from 'components/Picker' import subTypes from 'components/subTypes' import Search from 'components/Search'

export default new Router({ mode: 'history', scrollBehavior: () => ({ y: 0 }), routes: [ {path: '/', redirect: '/hello'}, {path: '/hello', component: Hello, children: [ {path: 'search', redirect: '/search'} ] }, {path: '/search', name: 'Search', component: Search}, {path: '/subtypes', name: 'subTypes', component: subTypes}, {path: '/orders', name: 'TabContainer', component: TabContainer}, {path: '/mine', name: 'Picker', component: Picker}, {path: '*', redirect: '/'} ] }) `