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

页面生命周期如何调用vue3 setup里的方法 #11384

Closed
ArtisanQ opened this issue Mar 3, 2022 · 7 comments
Closed

页面生命周期如何调用vue3 setup里的方法 #11384

ArtisanQ opened this issue Mar 3, 2022 · 7 comments
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@ArtisanQ
Copy link

ArtisanQ commented Mar 3, 2022

相关平台

微信小程序

复现仓库

https://github.com/NervJS/ta
小程序基础库: 2.6
使用框架: Vue 3

复现步骤

xxx

期望结果

xxx

实际结果

xxxx

环境信息

  Taro CLI 3.4.1 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
      npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD  
@taro-bot2 taro-bot2 bot added F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Mar 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

@AsherSun
Copy link

AsherSun commented Mar 5, 2022

方式一:

<script lang="ts" steup>
import { useDidShow } from '@tarojs/taro';
function fn () {
  consnole.log('fn')
}
useDidShow(() => {
  fn();
})
</script>

方式二:

<script lang="ts">
export default {
  setup() {
    const fn = () => {
      console.log('xxx')
    }
    return { fn }
  },
  onShow() {
    this.fn();
  }
}
</script>

方式三

<script lang="ts">
export default {
  methods: {
    fn() {
      console.log('xxx')
    }
  },
  onShow() {
    this.fn();
  }
}
</script>

@Chen-jj
Copy link
Contributor

Chen-jj commented Mar 12, 2022

@AsherSun 大佬稳!

@laizuan
Copy link

laizuan commented May 16, 2022

@AsherSun 方式一怎么使用onLoad呢?没有看到相关的hooks

@qsjc
Copy link

qsjc commented Jul 11, 2022

同好奇 如果使用script标签内 setup方式的话 小程序的生命周期函数如何运用啊?

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 11, 2022

同好奇 如果使用script标签内 setup方式的话 小程序的生命周期函数如何运用啊?

https://docs.taro.zone/docs/composition-api

@qsjc
Copy link

qsjc commented Jul 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

5 participants