Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taro对象在mobx方法中调用,发生异常 #1826

Closed
shuiruohanyu opened this issue Jan 6, 2019 · 8 comments
Closed

Taro对象在mobx方法中调用,发生异常 #1826

shuiruohanyu opened this issue Jan 6, 2019 · 8 comments

Comments

@shuiruohanyu
Copy link

shuiruohanyu commented Jan 6, 2019

定义一个工具类 在组件中引用此组件,工具类中使用了Taro的API ,

import  Taro from '@tarojs/taro';

  //获取所有的菜品数量 及价格 
export  function  getAllFoodInfo(){
	let  allPrice=0;//总价格
	let allNum=0;
	let store= Taro.getStorageSync(foodKey);//取菜品信息
	if(store){
		//对store进行遍历
		Object.keys(store).map((key)=>{
			if(store[key]){
			   allPrice+=store[key].price*store[key].Num;
			   allNum+=store[key].Num;
			}
		})
	}
	return {allPrice,allNum}
}

在组件中调用该方法 ok,

接入mobx,在组件中调用 this.props.对象.方法 该方法中 调用了 工具类的方法

import  {observable} from  'mobx';
import  {getAllFoodInfo} from  './common';
export default  observable({
    allObj:{},
    update(){
        this.allObj=getAllFoodInfo();
    }
})

但是调用时 出现异常 提示 taro不存在 getStorageSync方法 通过监视发现 同一个方法 组件中调用和mobx调用时 Taro的对象不同,此问题 不知道是何种原因所致

@taro-bot
Copy link

taro-bot bot commented Jan 6, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@luckyadam
Copy link
Member

根据你提供的代码片段未能复现问题,能否提供一个可以复现的小 demo

@luckyadam luckyadam added the mobx label Jan 13, 2019
@shuiruohanyu
Copy link
Author

shuiruohanyu commented Jan 14, 2019 via email

@nanjingboy
Copy link
Member

@shuiruohanyu 不好意思,能否给一个具体的 demo 呢?无法复现呢

@shuiruohanyu
Copy link
Author

shuiruohanyu commented Mar 26, 2019 via email

@nanjingboy
Copy link
Member

@shuiruohanyu 你的页面逻辑是什么样子呢?

@nanjingboy
Copy link
Member

@shuiruohanyu 根据你目前提供的信息并不能重现你所描述的问题,为了节约大家的时间,请提供完整可复现的 demo 出来。 谢谢 🙏

@luckyadam

@shuiruohanyu
Copy link
Author

shuiruohanyu commented Mar 26, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants