vuejs router - Require is not defined

跟風遠走 提交于 2019-12-02 17:23:25

问题


I am trying to get started with this: https://github.com/vuejs/vue-router

I have cloned the package, and followed the instructions to build:

npm install
npm run build

But I am receiving a "Require is not defined" error on:

var Vue = require('vue')
var VueRouter = require('../src')

in /example/example.js

I have installed node and browserify... Not sure what to do.


回答1:


Have you done the following after you installed Browserify?

1) bundle all your .js files into one file (e.g. 'bundle.js') using command:

browserify example/example.js -o bundle.js

2) put 'bundle.js' script into your .html file:

<script src="bundle.js"></script>

Important: Do not put 'example.js' script into .html file as 'bundle.js' already includes everything from your 'example.js' file.



来源:https://stackoverflow.com/questions/31658726/vuejs-router-require-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!