1. 使用 let that = this;

    demo(){
    	let that = this;
    	dd.getLocation({
    	  success(res) {
    		that.location = res;
    	  },
    	  fail() {
    		dd.alert({ title: '定位失败' });
    	  },
    	})
    }
    
  2. 使用箭头函数;

    demo(){
    	dd.getLocation({
    	  success:(res)=> {
    		this.location = res;
    	  },
    	  fail() {
    		dd.alert({ title: '定位失败' });
    	  },
    	})
    }
    
  3. 在成功方法内调用成功后需要执行的方法

    demo(){
    	let that = this
    	dd.getLocation({
    	  success:(res)=> {
    			that.demo1(res.data);
    	  },
    	  fail() {
    		dd.alert({ title: '定位失败' });
    	  },
    	})
    },
    demo1(val){
    	console,log(val);
    }
    
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐