vue中在vue.config.js中配置绝对路径和全局样式引入和跨域问题配置

1,373 阅读1分钟

1:配置绝对路径

configureWebpack: {        resolve: {            alias: {                '@': path.join(__dirname, 'src'),                'components': path.join(__dirname, 'src/components'),                'common': path.join(__dirname, 'src/common')            }        }    }

2:全局样式引入

 css: {        loaderOptions: {            stylus: {                import: ['~@/common/stylus/mixin.styl', '~@/common/stylus/variable.styl']            }        }    }

3:跨域问题配置

 devServer: { //跨域配置        proxy: {            '/api': {                target: "https://c.y.qq.com/musichall/fcgi-bin/",                // ws: true,                changOrigin: true,                pathRewrite: {                    '^/api': ''                }            }        },        before(app) {            app.get('/api/getDiscList', (req, res) => {                var url = 'https://c.y.qq.com/splcloud/fcgi-bin/'                axios.get(url, {                    headers: {                        referer: 'https://c.y.qq.com/',                        host: 'c.y.qq.com'                    },                    params: req.query                }).then((response) => {                    res.json(response.data)                }).catch((e) => {                    // console.log(e)                })            })        }