vue 学习遇到的问题
2019-03-06 本文已影响0人
响呼雷
一、接口请求(出现Request Method:OPTIONS)
首先安装axios:
1):npm install vue-axios --save
2):npm install qs.js --save
安装成功后,在main.js页面引用:
import Vue from 'vue'
import axios from 'axios'
import qs from 'qs'
Vue.prototype.axios
Vue.prototype.qs = qs //全局注册,使用方法为:this.qs
3):
this.$axios({
method:'post',
url:'api',
data:this.qs.stringify({ //这里是发送给后台的数据
userId:this.userId,
token:this.token,
})
}).then((response) =>{ //这里使用了ES6的语法
console.log(response) //请求成功返回的数据
}).catch((error) =>
console.log(error) //请求失败返回的数据
})
二、打包空白
image.png项目下config文件夹下的index.js,,将assetsPublicPath: '/'修改为assetsPublicPath: './'
三、图片不加载
image.png项目下build文件夹下的utils.js,添加publicPath: '../../',前提是你的css文件的中图片路径是这样的
image.png
之前我的是
image.png
这样打包还是不会显示的