·代码很简单,只是一个小demo,但是就是不能成功跑起来。
1.代码结构如下:
![clipboard.png](/img/bV5uSn)
2.index.html文件如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="divCon">
<h1>site : {{site}}</h1>
</div>
</body>
<script type="text/javascript" src="./dist/bundle.js"></script>
</html>
3.main.js如下:
var Vue = require('vue');
new Vue({
el: 'divCon',
data: {
site: "hello",
url: "www.runoob.com",
alexa: "10000"
}
})
4.webpack.config.js如下:
module.exports = {
entry: "./main.js",
output: {
filename: "bundle.js"
}
};
5.package.json文件如下:
{
"name": "portal",
"version": "1.0.0",
"description": "",
"main": "",
"scripts": {
"start": "webpack"
},
"author": "zhangying",
"license": "ISC",
"devDependencies": {
"babel-loader": "^7.1.4",
"css-loader": "^0.28.10",
"style-loader": "^0.20.3",
"vue": "^2.5.15",
"vue-loader": "^14.2.1",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.11"
},
"dependencies": {}
}
6.打包结果如下:
7.运行结果如下(chrome浏览器):
·一开始想是不是main.js中应该这么写:
var Vue = require('vue');
window.onload = new Vue({
el: 'divCon',
data: {
site: "hello",
url: "www.runoob.com",
alexa: "10000"
}
})
在页面加载完onload执行,如此试了下,依然不行。所以是不是配置的问题呢?求指导。。。
main.js中引入vue需要这样写:
原因移步至:https://segmentfault.com/q/10...