问题1:
问题描述:(同一组件下的方法之间的调用)同一个组件下方法A使用this.$options.methods.B调用方法B,然后方法B又使用this.$options.methods.C调用方法C,
方法B中报错typeError: Cannot read property 'methods' of undefined;且再将方法写在方法B中以后,报错:typeError: Cannot read property 'methods' of undefined
问题查找:在方法B中打印this.$options.methods,也同样报错为methods of undefined,继续向上查找,打印this.$options,又报错options of undefined,一直到打印this,发现this输出为实例中的$options.methods对象,而不是当前实例
问题原因:方法A调用方法B的方式问题,属性之间的符号(.)指属性访问符,对于方法,如果方法调用在某个对象上,那么方法中的this就是那个对象,因此在方法A中使用this.$options.methods.B的方式调用方法B以后,方法B中的this指向的就不是当前实例,而是指向的methods对象
解决方法:直接在方法A中使用this.B调用B,在方法B中使用this.C调用C。
问题2
问题描述:使用axios.post上传一个数组
解决方法:let param = { 'pks': JSON.stringify(g_tag_id)};
that.axios.post('mapHistory/subscribe.action', qs.stringify(param, {indices: false})).then()
问题三:报500,可能是axios.post 中请求的数据类型content-type设置有误
原因:当以application/json的content-type传送数据,被传送的对象只需被json序列化。当以application/x-www-form-urlencoded的方式传送数据。请求的内容需要以..=..&..=..的格式提交,在请求体内内容将会以”&”和“ = ”进行拆分。
解决:
1) Content-Type: application/json;charset=UTF-8
let params={anchorId:this.anchorForm.anchid};
this.axios.post(url, params).then()
2)Content-Type: application/x-www-form-urlencoded; charset=UTF-8
const params=new FormData();
params.append('anchorId',this.anchorForm.anchid);
this.axios.post(url, params).then()