From 9899bb9ea47548e934bd815a5379a2936cbff99b Mon Sep 17 00:00:00 2001
From: lizhihua <275091674@qq.com>
Date: Mon, 24 Apr 2017 11:33:26 +0800
Subject: [PATCH] Update webpack.config.js
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
```
// main.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import App from './App.vue'
Vue.use(VueRouter)
Vue.use(ElementUI)
const Foo = { template: '
foo
' }
const Bar = { template: 'bar
' }
// 2. 定义路由
// 每个路由应该映射一个组件。 其中"component" 可以是
// 通过 Vue.extend() 创建的组件构造器,
// 或者,只是一个组件配置对象。
// 我们晚点再讨论嵌套路由。
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
]
const router = new VueRouter({
routes // (缩写)相当于 routes: routes
})
new Vue({
el: '#app',
router,
render: h => h(App)
})
```
App.vue
```
{{ msg }}
Let's do it
Go to Foo
Go to Bar
```
跑官方示例报错,http://router.vuejs.org/zh-cn/essentials/getting-started.html
提示:[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
看了下这里的解决方案是:https://github.com/vuejs-templates/webpack/issues/215
---
webpack.config.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/webpack.config.js b/webpack.config.js
index b617dee9..bae08428 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -72,7 +72,8 @@ module.exports = (options = {}) => ({
],
resolve: {
alias: {
- '~': resolve(__dirname, 'src')
+ '~': resolve(__dirname, 'src'),
+ vue: 'vue/dist/vue.js'
}
},
devServer: {
@@ -92,4 +93,4 @@ module.exports = (options = {}) => ({
}
},
devtool: options.dev ? '#eval-source-map' : '#source-map'
-})
\ No newline at end of file
+})