vue 在axios中使用路由跳转并传参,报Cannot read property '$router' of undefined

在用vue开发项目时,需要经A页面的参数以及页面中axios返回的参数传递到B页面,直接上代码吧(简单写了):

data() {
			return {
				imageUrl: require("../../static/tianjia.png"),
				dateValue1: "2018-09-08",
				dateValue2: "2018-09-10",
				}
	}
methods: {
	//通过这个方法去进行路由跳转以及传参
	 handleClick(row){
                var me=this;
                var features;        
                me.axios.get(
                    'personnelface/common/featurebyurl?face_img_url='+row.face_img_url)
                    .then(function(response){
                    if(response.data.code==0){                     
                        features=response.data.msg.feature;     
                        this.$router.push({ path: '/App/FootholdAnalysis', query:{ imageUrl:row.face_img_url, dateValue1: this.dateValue1, dateValue2:this.dateValue2,features:features}}); 
                        $('.FrequencyAnalysis').removeClass('analysisButtonActive');  
                        $('.FootholdAnalysis').addClass('analysisButtonActive');                        
                    }
                })
                .catch(function (error) {
						console.log(error);
                    });                   
            }
}		

但是上述写法,报错Cannot read property ‘$router’ of undefined,通过debugger追踪发现下面代码中this显示未定义,在上述代码中,定义this用错:

this.$router.push({ path: '/App/FootholdAnalysis', query:{ imageUrl:row.face_img_url, dateValue1: this.dateValue1, dateValue2:this.dateValue2,features:features}}); 

对上述代码进行修改:

 handleClick(row){
                var me=this;
                var features;
                this.axios.get(
                    'personnelface/common/featurebyurl?face_img_url='+row.face_img_url)
                    .then(function(response){
                    if(response.data.code==0){                     
                        features=response.data.msg.feature;     
                        me.$router.push({ path: '/App/FootholdAnalysis', query:{ imageUrl:row.face_img_url, dateValue1: me.dateValue1, dateValue2:me.dateValue2,features:features}}); 
                        $('.FrequencyAnalysis').removeClass('analysisButtonActive');  
                        $('.FootholdAnalysis').addClass('analysisButtonActive');                        
                    }
                })
                .catch(function (error) {
						console.log(error);
                    });                                 
            }

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值