axios的使用:
/** * * 使用axios的步骤; * 第一步安装 npm install --save axios vue-axios 第二步,在mian.js中导入和配置, 引入: import axios from ‘axios‘
Vue.use(axios) 配置 : axios.defaults.baseURL="https://wd4363557576ckikwp.wilddogio.com/" 第三步在你要使用的文件下引用axios */
axios 发送数据:
const fromData={
age:this.ruleForm.age,
pass:this.ruleForm.pass
}
//发送数据
axios.post(‘./axiosT.json‘,fromData)
.then(res=>{//当数据发送成功时回调
console.log("数据发送成功")
console.log(res.data)
})
.catch((error)=>{
console.log(error)
})
接受数据:
mounted () {
var that = this
axios.get(‘/Produce.json‘)
.then(function(response){
console.log(response.data)
that.produce=response.data
})
}