dcloudio / uni-app

A cross-platform framework using Vue.js
https://uniapp.dcloud.io
Apache License 2.0
40.1k stars 3.63k forks source link

【报Bug】百度小程序安卓端computed无效 #2024

Closed Functionprototype closed 10 months ago

Functionprototype commented 4 years ago

PC开发环境操作系统: Windows PC开发环境操作系统版本号: win10企业版 HBuilderX类型: 正式 第三方开发者工具版本号: 3.12.1 基础库版本号: 3.190.255-rc 项目创建方式: CLI CLI版本号: 2.0.0-24220191115006

//父组件
<template>  
  <view>  
    <demo :testData="testData"></demo>  
  </view>  
</template>  

<script>  
import demo from "./demo.vue";  
export default {  
  data() {  
    return {  
      testData: {},  
    };  
  },  
  components: {  
    demo,  
  },  
  onLoad() {},  
  created() {  
    setTimeout(() => {  
      console.log("更新testData");  
      this.testData = { num: 200 };  
    }, 5000);  
  },  
  methods: {},  
};  
</script>  
//子组件
<template>  
  <view>  
    <view>props -- {{ testData.num }}</view>  
    <view>computed -- {{ cTestData.num }}</view>  
  </view>  
</template>  

<script>  
export default {  
  props: {  
      testData:{  
          default:{}  
      }  
  },  
  computed: {  
    cTestData() {  
      return { num: this.testData.num + 100 };  
    },  
  },  
};  
</script> 

//package.json

"dependencies": {  
"@dcloudio/uni-app-plus": "",  
"@dcloudio/uni-h5": "",  
"@dcloudio/uni-mp-alipay": "",  
"@dcloudio/uni-mp-baidu": "",  
"@dcloudio/uni-mp-qq": "",  
"@dcloudio/uni-mp-toutiao": "",  
"@dcloudio/uni-mp-weixin": "*",  
"@dcloudio/uni-stat": "0.0.113",  
"cos-wx-sdk-v5": "^0.7.10",  
"crypto-js": "^3.1.9-1",  
"flyio": "^0.6.2",  
"md5": "^2.2.1",  
"regenerator-runtime": "^0.12.1",  
"sa-sdk-miniprogram": "^1.13.23",  
"underscore": "^1.9.2",  
"url-parse": "^1.4.7",  
"uuidjs": "^4.2.4",  
"vue": "2.6.10",  
"vuex": "^3.0.1"  
},  
"devDependencies": {  
"@dcloudio/uni-cli-shared": "0.2.994",  
"@dcloudio/uni-template-compiler": "0.9.183",  
"@dcloudio/vue-cli-plugin-hbuilderx": "2.0.0-24220191115006",  
"@dcloudio/vue-cli-plugin-uni": "2.0.0-24220191115006",  
"@dcloudio/vue-cli-plugin-uni-optimize": "2.0.0-24220191115006",  
"@dcloudio/webpack-uni-mp-loader": "0.3.644",  
"@dcloudio/webpack-uni-pages-loader": "0.2.875",  
"@types/html5plus": "1.0.0",  
"@types/uni-app": "1.4.1",  
"@vue/cli-plugin-babel": "3.5.1",  
"@vue/cli-service": "^3.11.0",  
"babel-plugin-import": "^1.11.0",  
"http-server": "^0.12.1",  
"postcss-comment": "^2.0.0",  
"shelljs": "^0.8.3",  
"terser-webpack-plugin": "^2.3.4",  
"webpack-preprocessor-loader": "^1.1.2",  
"yargs": "^15.1.0"  
},  
"browserslist": [  
"last 3 versions",  
"Android >= 4.4",  
"ios >= 8"  
],  
"uni-app": {  
"scripts": {}  
}

操作步骤: 用百度小程序工具加载程序, 用安卓手机真机调试

预期结果: computed值会改变, 子组件会随父组件更新

实际结果: computed值不会改变, 子组件不会随父组件更新

bug描述: computed监听父组件传递过来的props无效, 父组件更新数据, 子组件不更新

微信小程序, 支付宝小程序均可以, 百度小程序ios端可以, 安卓端子组件不更新导致白屏

附件中为编译后的程序, 百度小程序安卓端子组件computed不更新, 已咨询过百度小程序开发人员反馈是uniapp框架的原因

社区问题地址 : https://ask.dcloud.net.cn/question/103666

Missna commented 4 years ago

没人解决问题吗?

zhetengbiji commented 4 years ago

没人解决问题吗?

有有,你在github发一下,社区又发一下,我被你吊着跑。。。

zhetengbiji commented 4 years ago

你更新到 2.0.0-28620200814004 试试

Missna commented 4 years ago

多谢多谢,因为之前在社区发了一直没有人回,所以只能广撒网了,我们试一下

Functionprototype commented 4 years ago

@zhetengbiji 更新到了2.0.0-28820200820001 在安卓端还是不行了 , computed不更新

代码如下: index.vue

<template>
  <view>
    <demo :testData="pData" :testData2="pData2"></demo>
  </view>
</template>

<script>
import demo from "./demo.vue";
export default {
  name: "pa",
  data() {
    return {
      pData: [],
      pData2: { num: 111 },
    };
  },
  components: {
    demo,
  },
  onLoad() {},
  created() {
    setTimeout(() => {
      // 模拟接口收到数据
      this.pData = [{ name: "test1" }, { name: "test2" }, { name: "test3" }];
      this.pData2 = { num: 222 };
    }, 3000);
  },
  methods: {},
};
</script>

<style></style>

demo.vue

<template>
  <view>
    <template v-for="(item, index) in testData">
      <view :key="item.name">
        {{ item.name }}
        {{ cTestData[index].name }}
      </view>
    </template>
    <template>
      <view> testData2 -- {{ testData2.num }} </view>
      <view> cTestData2 -- {{ cTestData2.num }} </view>
    </template>
  </view>
</template>

<script>
export default {
  name: "demo",
  mounted() {},
  data() {
    return {};
  },
  props: {
    testData: {
      default: [],
    },
    testData2: {
      default: {},
    },
  },
  computed: {
    cTestData() {
      return this.init();
    },
    cTestData2() {
      return { num: this.testData2.num + 1000 };
    },
  },
  methods: {
    init: function() {
      var myList = [];
      var source = this.testData;
      for (var i = 0; i < source.length; i++) {
        myList.push({
          name: source[i].name + Math.random(),
        });
      }
      return myList;
    },
  },
  watch: {
    testData: function() {
      console.log("testData更新");
    },
  },
};
</script>

<style></style>

package.json

{
  "name": "my-project",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "npm run dev:h5",
    "build": "npm run build:h5",
    "build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
    "build:custom": "cross-env NODE_ENV=production uniapp-cli custom",
    "build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build",
    "build:mp-360": "cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build",
    "build:mp-alipay": "cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build",
    "build:mp-baidu": "cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build",
    "build:mp-qq": "cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build",
    "build:mp-toutiao": "cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build",
    "build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
    "build:quickapp-native": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-native vue-cli-service uni-build",
    "build:quickapp-webview": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview vue-cli-service uni-build",
    "build:quickapp-webview-huawei": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build",
    "build:quickapp-webview-union": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build",
    "dev:app-plus": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch",
    "dev:custom": "cross-env NODE_ENV=development uniapp-cli custom",
    "dev:h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve",
    "dev:mp-360": "cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch",
    "dev:mp-alipay": "cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch",
    "dev:mp-baidu": "cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch",
    "dev:mp-qq": "cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch",
    "dev:mp-toutiao": "cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch",
    "dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
    "dev:quickapp-native": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-native vue-cli-service uni-build --watch",
    "dev:quickapp-webview": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview vue-cli-service uni-build --watch",
    "dev:quickapp-webview-huawei": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build --watch",
    "dev:quickapp-webview-union": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build --watch",
    "info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js",
    "serve:quickapp-native": "node node_modules/@dcloudio/uni-quickapp-native/bin/serve.js",
    "test:android": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=android jest -i",
    "test:h5": "cross-env UNI_PLATFORM=h5 jest -i",
    "test:ios": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=ios jest -i",
    "test:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu jest -i",
    "test:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin jest -i"
  },
  "dependencies": {
    "@dcloudio/uni-app-plus": "^2.0.0-28820200820001",
    "@dcloudio/uni-h5": "^2.0.0-28820200820001",
    "@dcloudio/uni-helper-json": "*",
    "@dcloudio/uni-mp-360": "^2.0.0-28820200820001",
    "@dcloudio/uni-mp-alipay": "^2.0.0-28820200820001",
    "@dcloudio/uni-mp-baidu": "^2.0.0-28820200820001",
    "@dcloudio/uni-mp-qq": "^2.0.0-28820200820001",
    "@dcloudio/uni-mp-toutiao": "^2.0.0-28820200820001",
    "@dcloudio/uni-mp-vue": "^2.0.0-28820200820001",
    "@dcloudio/uni-mp-weixin": "^2.0.0-28820200820001",
    "@dcloudio/uni-quickapp-native": "^2.0.0-28820200820001",
    "@dcloudio/uni-quickapp-webview": "^2.0.0-28820200820001",
    "@dcloudio/uni-stat": "^2.0.0-28820200820001",
    "@vue/shared": "^3.0.0-rc.4",
    "core-js": "^3.6.5",
    "flyio": "^0.6.2",
    "regenerator-runtime": "^0.12.1",
    "vue": "^2.6.11",
    "vuex": "^3.2.0"
  },
  "devDependencies": {
    "@dcloudio/types": "*",
    "@dcloudio/uni-automator": "^2.0.0-28820200820001",
    "@dcloudio/uni-cli-shared": "^2.0.0-28820200820001",
    "@dcloudio/uni-migration": "^2.0.0-28820200820001",
    "@dcloudio/uni-template-compiler": "^2.0.0-28820200820001",
    "@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.0-28820200820001",
    "@dcloudio/vue-cli-plugin-uni": "^2.0.0-28820200820001",
    "@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.0-28820200820001",
    "@dcloudio/webpack-uni-mp-loader": "^2.0.0-28820200820001",
    "@dcloudio/webpack-uni-pages-loader": "^2.0.0-28820200820001",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "babel-plugin-import": "^1.11.0",
    "cross-env": "^7.0.2",
    "jest": "^25.4.0",
    "mini-types": "*",
    "miniprogram-api-typings": "*",
    "postcss-comment": "^2.0.0",
    "vue-template-compiler": "^2.6.11"
  },
  "browserslist": [
    "Android >= 4",
    "ios >= 8"
  ],
  "uni-app": {
    "scripts": {}
  }
}