匯入方式如下:import 'vue-resource'
元件使用post:
<script>
export default{
data () {
return {
formSendCodeField:{
phone: '',
code: ''
}
}
},
methods: {
sendCode () {
this.$http.post('/api/phone/code', {phone: this.phone})
.then(function (response) {
console.log(response);
}, function(error){
console.log(error)
})
}
}
}
</script>
報錯訊息為:cannot read property "post" of ubdefined
你用的是webpack嗎?webpack的話是這樣用