想尝试一下Vue和后台的对接
写好了准备调试的时候发现显示:Cannot read property 'store' of undefined
编程小白一个,求懂行的大佬指点指点,多谢
代码如下:
<template>
<el-button type="primary" @click="test()">测试接口</el-button>
</template>
<script>
export default {
data() {
return {
store:[ { store_id:'555', store_name:'虎牙', store_password:'123456', store_address:'广州', store_phone:'123456' } ]
}
methods: { test:()=>{ const _this=this; console.log(this.store); axios.post('http://localhost:8081/store/add/',this.store).then( (resp)=>{ if (resp.data > 1) { _this.$alert(_this.store.store_name + '添加成功!', '消息', { confirmButtonText: '确定', callback: action => { _this.closeAddDialog(); } }) } }) },
}
<script>
test:()=>换成 test()试试
this指向有问题,没有指向vue实例
_this.store[0].store_name
test(){ axios.post('http://localhost:8081/store/add/',this.store).then( (resp)=>{ if (resp.data > 1) { this.$alert(this.store[0].store_name + '添加成功!', '消息', { confirmButtonText: '确定', callback: action => { this.closeAddDialog(); } }) } }) },