Vue2 笔记本项目遇到的坑

299 阅读1分钟

webstorm 报错

使用Eslint检验项目报错“Component name “Error“ should always be multi-word“解决办法

编辑 .eslintrc.js

module.exports = {
  ……
  overrides: [
    {
      files: ['src/views/**/*.vue'],
      rules: {
        'vue/multi-word-component-names': 0,
      },
    },
  ]
}

image.png

image.png

跨域请求携带 cookie

f15a59ae091e62fd46ffb9dabb721db.png

import axios from 'axios'
import baseURLConfig from './config-baseURL'
import {Message} from 'element-ui'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.baseURL = baseURLConfig.baseURL
axios.defaults.withCredentials = true

chrome在2020年3月份升级了安全策略,对于跨域请求如果想写入cookie,必须是https的网站才可以。对于http的网站,cookie写入总是失败。

解决方案:

第一步 修改build/webpack.dev.conf 文件,在devServer里添加https: true, 如下图

image.png

image.png

第二步

执行 npm start, 浏览器输入 https://localhost:8080 。注意是https, 不是 http
此时并不能打开页面,而是显示如下

image.png

image.png

解决:就是在当前页面用键盘输入 thisisunsafe ,不是在地址栏输入,就直接敲键盘就行了,页面即会自动刷新进入网页。
因为Chrome不信任这些自签名ssl证书,为了安全起见,直接禁止访问了,thisisunsafe 这个命令,说明你已经了解并确认这是个不安全的网站,你仍要访问就给你访问了。

第三步
代码里使用接口时都需要指明使用https的接口,比如 https://note-server.hunger-valley.com/***

部署到 github 时,路径多出 /static/css ,无法加载 element-ui 的图标

1652210279147.png

解决方法:

第一步:build/utils 文件中,添publicPath:'../../'

image.png

第二步:config/index.js 文件中,assetsPublicPath:后面改为 ./

image.png