1.在一个vue-cli3项目中,需要两个端口号,(vue-cli3,node服务) cnpm i concurrently -D 在package.json 中进行配置:
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"server": "nodemon server.js",
"dev": "concurrently \"npm run serve\" \"npm run server\" "
}
2.vue.config.js中的常用配置:
const path = require('path')
const appData = require("./data.json");
const seller = appData.seller;
const goods = appData.goods;
const ratings = appData.ratings;
module.exports = {
configureWebpack: {
resolve: {
alias: {
'components': path.join(__dirname, 'src/components')
}
}
},
css: {
loaderOptions: {
stylus: {
import: ['~@/assets/style/index.styl', '~@/assets/style/demo.styl']
}
}
},
devServer: { //跨域配置
proxy: {
'/api': {
target: "http://localhost:8088/",
ws: true,
changOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
before(app) { //mock数据的配置
app.get('/api/seller', (req, res, next) => {
res.json({
errno: 0,
data: seller
});
}),
app.get('/api/goods', (req, res, next) => {
res.json({
errno: 0,
data: goods
});
}),
app.get('/api/ratings', (req, res, next) => {
res.json({
errno: 0,
data: ratings
});
})
}
}
}
后续会持续更新,希望大家多多支持,多多给意见。学习笔记