博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue-cli-element-ui-scss-axios
阅读量:5901 次
发布时间:2019-06-19

本文共 3883 字,大约阅读时间需要 12 分钟。

hot3.png

初始化

cnpm i vue-cli -gvue init webpack htmlcd htmlcnpm i node-sass sass-loader less less-loader -Dcnpm i element-ui -Scnpm i axios qs js-cookie -Snpm run dev

src/assets/scss/element-variables.scss

$--color-primary: #315ca1 !default;$--font-path: '../../../node_modules/element-ui/lib/theme-chalk/fonts';@import "../../../node_modules/element-ui/packages/theme-chalk/src/index";

src/config.js

export default {    title: '云管理系统',    baseUrl: 'http://localhost:13000/api/msweb',}

src/http.js

import axios from 'axios'import qs from 'qs'import cache from './cache'import Config from './config'const Axios = axios.create({    baseURL: Config.baseUrl,    timeout: 8000,    responseType: 'json',    headers: {        'Content-Type': 'application/x-www-form-urlencoded'    }})Axios.interceptors.request.use(    http => {        http.data = qs.stringify(http.data);        let token = cache.get('userToken') || '';        if (token != '') {            http.headers.Authorization = `token ${token}`;            http.headers.Timestamp = cache.get('userTokenExpireOut') || 0;        }        return http;    },    error => {        return Promise.reject(error);    })Axios.interceptors.response.use( // 响应拦截器    response => {        if (response.status == 401) {            cache.remove('userToken')            cache.remove('userRole')        }        return response;    },    error => {        return Promise.reject(error);    })export default Axios;

src/cache.js

import cookies from 'js-cookie'let cache = {    prefix: window.location.host}cache.set = function (name, value) {    cookies.set(this.prefix + '_' + name, value || null);}cache.get = function (name) {    return cookies.get(this.prefix + '_' + name);}cache.remove = function (name) {    cookies.remove(this.prefix + '_' + name);}export default cache

src/main.js

import Vue from 'vue'import ElementUI from 'element-ui';import './assets/scss/element-variables.scss'import './assets/iconfont/iconfont.css'import main from './components/layout/main.vue'import router from './router'import http from './http'import cache from './cache'Vue.use(ElementUI)Vue.prototype.$http = httpVue.prototype.$cache = cacheVue.config.productionTip = falsenew Vue({    el: '#app',    router,    render: h => h(main),})

src/app.vue

src/components/test.vue

src/components/test.scss

$color: red;h3 {    color: $color;}

多页面 build/utils.js

const fs = require('fs')const glob = require('glob')var entryPath = path.resolve(__dirname, '../src/entry')var htmlPath = path.resolve(__dirname, '../src/html')exports.entries = function () {    var entryFiles = glob.sync(entryPath + '/*.js')    var map = {}    entryFiles.forEach((filePath) => {        var filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))        map[filename] = filePath    })    return map}exports.htmlPlugin = function () {    let entryHtml = glob.sync(htmlPath + '/*.html')    let arr = []    entryHtml.forEach((filePath) => {        let filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))        let conf = {            template: filePath,            filename: filename + '.html',            inject: false        }        if (fs.existsSync(entryPath + '/' + filename + '.js') == true) {            conf.inject = true;            conf.chunks = ['manifest', 'vendor', filename];        }        if (process.env.NODE_ENV === 'production') {            conf = merge(conf, {                minify: {                    removeComments: true,                    collapseWhitespace: true,                    removeAttributeQuotes: true                },                chunksSortMode: 'dependency'            })        }        arr.push(new HtmlWebpackPlugin(conf))    })    return arr}

转载于:https://my.oschina.net/qiongtaoli/blog/1842458

你可能感兴趣的文章
c#创建文件夹
查看>>
Hibernate事务代码规范写法
查看>>
网络最大流问题算法小结 [转]
查看>>
面试之Java知识整理
查看>>
iOS推送消息报错误“Domain=NSCocoaErrorDomain Code=3000”的可能问题
查看>>
kvm-1
查看>>
hdu1045 Fire Net---二进制枚举子集
查看>>
leetcode 64. Minimum Path Sum
查看>>
textkit
查看>>
CentOS7+CDH5.14.0安装CDH错误排查: HiveServer2 该角色的进程已退出。该角色的预期状态为已启动...
查看>>
The Oregon Trail 俄勒冈之旅
查看>>
Excel VBA连接MySql 数据库获取数据
查看>>
Developing a Service Provider using Java API(Service Provider Interface)(转)
查看>>
BAE Flask UEditor 使用七牛云
查看>>
Bootstrap系列 -- 15. 下拉选择框select
查看>>
【转载】无限级分类的简单实例
查看>>
关于WinPE安装操作系统
查看>>
LeetCode Median of Two Sorted Arrays
查看>>
oschina程序开发
查看>>
mysql创建每月执行一次的event
查看>>