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

vue2中 provide/inject 在H5和小程序中的差异 #4453

Open
hewx815 opened this issue Jul 29, 2023 · 0 comments
Open

vue2中 provide/inject 在H5和小程序中的差异 #4453

hewx815 opened this issue Jul 29, 2023 · 0 comments

Comments

@hewx815
Copy link

hewx815 commented Jul 29, 2023

问题描述
vue2中 provide/inject 用法,provide一个对象,h5中可以实现响应式,小程序异常

复现步骤

// TestPage.vue
<template>
  <view>
    <view>TestPage num:{{ num }}</view>
    <button @click="num += 1">
      +
    </button>
    <TestCom />
  </view>
</template>

<script>
import TestCom from './TestCom.vue';

export default {
  components: { TestCom },
  provide() {
    return { TestPage: this };
  },
  data() {
    return {
      num: 1,
    };
  },
};
</script>
// TestCom.vue
<template>
  <view>
    TestCom num: {{ TestPage.num }}
    <view />
  </view>
</template>

<script>
export default {
  inject: ['TestPage'],
  created() {
    console.log(this.TestPage.num);
  },
};
</script>

预期结果
h5中可以实现响应式
h5

实际结果
微信小程序中异常
weixin

系统信息:

  • 发行平台: 微信小程序、H5平台
  • 操作系统: Windows 10 专业版 22H2 19045.3208
  • uni-app版本: 2.0.2-3080720230703001
  • 设备信息: iPhone6/7/8

补充信息
如果是产品特性应该在文档内明确指出,免得开发者掉坑里出不来 .

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

1 participant