vue中图⽚、⽂件上传
记录下项⽬中遇到的图⽚上传,亦或者⽂件上传的⽅式,总是遗忘,查资料好慢
项⽬采⽤的vue-element-admin 使⽤vue/vuex/vue-router/element-ui技术开发
由于request.js封装的接⼝类型,都是基于普通接⼝的请求,没有封装⽂件上传的接⼝类型
request.js代码如下
import axios from 'axios'
import { Message } from 'element-ui'
import store from '@/store'
import { getToken, removeToken, removeUserMenu, removeUserId } from '@/utils/auth'
import router from '@/router/index'
// create an axios instance
const service = ate({
baseURL: v.VUE_APP_BASE_API + '/' + v.VUE_APP_API_VERSION,
// withCredentials: true, // send cookies when cross-domain requests
timeout: 5000 // request timeout
normalmode})sq5
// request interceptor
quest.use(
config => {
if (ken) {
config.headers['authorization'] = 'Bearer ' + getToken()
}
/
雪佛兰景程论坛/ console.log(config)
const tthash = window.btoa(
window
.btoa(encodeURI(place('#/', '') ?? ''))
.split('')
.reverse()
.join('')
)
if (hod == 'post') {
config.data = {
...config.data,
ttname: place('/', ''),
tthash: tthash,
tenantCode: v.NODE_ENV === 'development' ? v.VUE_APP_TENANT_CODE : '',                productCode: v.NODE_ENV === 'development' ? v.VUE_APP_PRODUCT_CODE : ''            }
} else if (hod == 'get') {
config.params = {
...config.params,
ttname: place('/', ''),
tthash: tthash
}私家车强制报废年限
}
return config
},
error => {
ject(error)
}
东风本田汽车配件)
// response interceptor
sponse.use(
response => {
const { code, message } = response.data
怎么买汽车保险
// 返回正常结果
if (code == 10000) return response.data
Message({
message: message || 'Error',
type: 'warning',
后续会持续更新