Vuejs - 未定义要求
Vuejs - require is not defined
我只是在玩 vuejs 路由器并尝试加载一个组件。
我使用示例代码并更改了 foo
// 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
。
我哪里错了?
require
是 NodeJS 环境中的内置函数,用于 Grunt 构建环境。
如果您还想在浏览器环境中使用它,您可以集成它的这个版本:http://requirejs.org
(作者)这是过时的:
使用 Browserify
或 Webpack
,因为 Vue 社区提供了积极的支持
http://vuejs.org/guide/application.html#Deploying_for_Production(死link)
我个人使用了 Vue GitHub-org 的 this repo 来快速上手。
Edit:
This has moved on a bit in early 2018.
Deployment guide: https://vuejs.org/v2/guide/deployment.html
'getting started' type repo: https://github.com/vuejs/vue-loader
我只是在玩 vuejs 路由器并尝试加载一个组件。
我使用示例代码并更改了 foo
// 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
。
我哪里错了?
require
是 NodeJS 环境中的内置函数,用于 Grunt 构建环境。
如果您还想在浏览器环境中使用它,您可以集成它的这个版本:http://requirejs.org
(作者)这是过时的:
使用 Browserify
或 Webpack
,因为 Vue 社区提供了积极的支持
http://vuejs.org/guide/application.html#Deploying_for_Production(死link)
我个人使用了 Vue GitHub-org 的 this repo 来快速上手。
Edit:
This has moved on a bit in early 2018.Deployment guide: https://vuejs.org/v2/guide/deployment.html
'getting started' type repo: https://github.com/vuejs/vue-loader