vue开发须知
2021-01-27 本文已影响0人
zlf_j
lang="less"报错,原因是less-loader版本过高
解决办法:将less-loader的版本降低
1、在package.js中找到less-loader,将版本号改为 ^5.0.0;
2、然后再执行npm install less-loader@5.0.0 --save。
https://blog.csdn.net/l244112311/article/details/105844036
axios.defaults.withCredentials = true;
- 默认情况下,跨源请求不提供凭据(cookie、HTTP认证及客户端SSL证明等)。通过将withCredentials属性设置为true,可以指定某个请求应该发送凭据。
- 后端需要带cookie过去,而前端没有设置为true,所以导致cookie传不过去
- 当配置了 withCredentials = true时,必须在后端增加 response 头信息Access-Control-Allow-Origin,且必须指定域名,而不能指定为*!!!
https://www.cnblogs.com/hehuiqiong/p/13132226.html - vue不会自动保存后端传来的cookie
https://blog.csdn.net/qq_39611230/article/details/108090828
Vuex namespaced: true配置
- 使其成为带命名空间的模块。保证在变量名一样的时候,添加一个父级名拼接
https://blog.csdn.net/qq_40410916/article/details/108121892
Uncaught TypeError: routes.forEach is not a function
vue创建项目报错
Command vue init requires a global addon to be installed.
Please run yarn global add @vue/cli-init
image.png
- 解决办法:先执行以下命令
npm install -g @vue/cli-init
https://blog.csdn.net/weixin_42886893/article/details/107022876
less报错
* !!vue-style-loader!css-loader?{"sourceMap":true}
!../../node_modules/vue-loader/lib/style-compiler/index? .......
image.png
- 原因:缺少相关依赖
- 解决办法:npm install less less-loader --save-dev
https://www.jianshu.com/p/72e3af3fa747
vue项目打包后,dist里有文件报错404
- 修改config/index.js
assetsPublicPath: './' // 将'/'改成'./'
https://blog.csdn.net/miss_liangrm/article/details/98534134
- 如果router里设置了base值,则设置为该目录
const router = new Router({
base: 'treat',
mode: 'history'
});
assetsPublicPath: '/treat/' // ***
Vue+elementUI build打包后字体图标丢失问题
解决办法:
build目录下utils.js,添加 publicPath: '../../'
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader',
publicPath: '../../' // 修改
})
} else {
return ['vue-style-loader'].concat(loaders)
}
https://blog.csdn.net/qq_38543537/article/details/90755830
vue配置dev、test、pro环境,实现分环境打包
https://www.pianshen.com/article/57691807884/
webpack 在index.html里面区分环境变量(process.env.NODE_ENV)
<script>
if ('<%= process.env.NODE_ENV %>' === 'development') {
window.SITE_CONFIG['apiURL'] = '/api'; // prod_api // api请求地址
} else {
window.SITE_CONFIG['apiURL'] = '/prod_api'; //
}
</script>
https://blog.csdn.net/xiaomogg/article/details/102549753
网页title的logo小图标
- 图片需要放在static里引入,本地才会展示
<link rel="shortcut icon" type="image/x-icon" href="./static/img/logo.png" />
PC端网页基本设置
<title>标题</title>
<meta name="description" content='内容长一点' />
<meta name="keywords" content='内容短一点' />
<link rel="shortcut icon" type="image/x-icon" href="./static/img/logo.png"/>
移动端网页适配
<meta id="viewport" content="width=device-width, user-scalable=yes,initial-scale=1" name="viewport" />
<script>
var detectBrowser = function(name) {
if (navigator.userAgent.toLowerCase().indexOf(name) > -1) {
return true;
} else {
return false;
}
};
var width = parseInt(window.screen.width);
var scale = width / 640; // 根据设计稿尺寸进行相应修改:640=>?
var userScalable = 'no';
if (detectBrowser("qq/")) userScalable = 'yes';
document.getElementById('viewport').setAttribute(
'content', 'target-densitydpi=device-dpi,width=1445,user-scalable=' + userScalable + ',initial-scale=' + scale); // 这里也别忘了改:640=>?
</script>