NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.35k stars 4.77k forks source link

vue3 <script <setup>语法糖里面的方法与<script>混用时,在<script>onShow,onPullDownRefresh等生命周期内,build的时读取不到,dev时没问题 #10456

Closed CaicoLeung closed 2 years ago

CaicoLeung commented 2 years ago

相关平台

微信小程序

小程序基础库: 2.19.6 使用框架: Vue 3

复现步骤

<script lang="ts">
export default {
  onShow() {
    this.store.dispatch("requestShopCartList");
    this.store.dispatch("requestPalletCartList");
  }
};
</script>

<script lang="ts" setup>
import { computed, ref, watch } from "vue";
import GoodsCart from "#/tarbar/shopcart/GoodsCart.vue";
import PalletCart from "#/tarbar/shopcart/PalletCart.vue";
import { useStore } from "#/store";
import Taro from "@tarojs/taro";

const store = useStore();
</script>

期望结果

onShow内部可以访问this, 获取setup内部的变量

实际结果

this为undefined

环境信息

taro CLI 3.3.9 environment info:
    System:
      OS: macOS 12.0
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.10.0 - /usr/local/bin/node
      Yarn: 1.22.15 - /usr/local/bin/yarn
      npm: 7.24.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.3.10 => 3.3.10
      @tarojs/mini-runner: 3.3.10 => 3.3.10
      @tarojs/runtime: 3.3.10 => 3.3.10
      @tarojs/taro: 3.3.10 => 3.3.10
      @tarojs/webpack-runner: 3.3.10 => 3.3.10
      babel-preset-taro: 3.3.10 => 3.3.10
      eslint-config-taro: 3.3.10 => 3.3.10
CaicoLeung commented 2 years ago

目前的暂行办法是, 放弃<script 语法糖, 只用一个 Githubissues.

  • Githubissues is a development platform for aggregating issues.