我只是玩弄vuejs路由器並嘗試加載組件。 我使用的樣例代碼和改變foo
Vuejs - require is not defined
// Define some components
var Foo = Vue.extend({
template: require('./components/test.vue')
});
var Bar = Vue.extend({
template: '<p>This is bar!</p>'
});
// The router needs a root component to render.
// For demo purposes, we will just use an empty one
// because we are using the HTML as the app template.
var App = Vue.extend({})
// Create a router instance.
// You can pass in additional options here, but let's
// keep it simple for now.
var router = new VueRouter()
// Define some routes.
// Each route should map to a component. The "component" can
// either be an actual component constructor created via
// Vue.extend(), or just a component options object.
// We'll talk about nested routes later.
router.map({
'/foo': {
component: Foo
},
'/bar': {
component: Bar
}
})
// Now we can start the app!
// The router will create an instance of App and mount to
// the element matching the selector #app.
router.start(App, '#app')
我也
Vue.component('Foo', {
template: require('./components/test.vue')
})
測試它在我的test.vue
我有
<template>
<h2>Test</h2>
</template>
但不是隻要我使用require
我得到每次在我的開發工具中發現錯誤Required is not defined
。
我在這裏錯了什麼?
呀 - 感謝爲你的答案。我已經想通了,因爲'required',現在我正在使用http://browserify.org/ – bobbybackblech