taro onChooseAvatar回调不生效

w3nuxt5m  于 4个月前  发布在  其他
关注(0)|答案(8)|浏览(51)

相关平台

微信小程序

小程序基础库: 2.27.1
使用框架: React

复现步骤

<Button
open-type="chooseAvatar"
className="avatorBtn"
onChooseAvatar={(e) => {
console.log(e, '-wwwwwe')
this.chooseAvatar(e)
}}
plain={true}

期望结果

微信关闭getUserInfo功能后 使用taro的Button组件openType=chooseAvatar时点击后onChooseAvatar无回调

实际结果

希望点击后有回调并且拿到微信头像

环境信息

Taro CLI 3.2.8 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 12.22.6 - C:\Program Files\nodejs\node.EXE
      npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
atmip9wb

atmip9wb1#

你的taro版本不够,至少需要升级到3.4.3

y1aodyip

y1aodyip2#

onChooseAvatar 返回的类型为 any ,是否有计划补全类型

6za6bjd0

6za6bjd04#

同样问题 我taro版本是3.6.2,但是获取不到微信头像

<template>
  <view class="index">
    <button class="avatar-wrapper" open-type="chooseAvatar" onChooseAvatar="onChooseAvatar">
      <img class="avatar" src="{{avatarUrl}}" />
    </button>
    <input type="nickname" class="weui-input" placeholder="请输入昵称" v-model="nickName" />
  </view>
</template>

<script>
import { reactive, toRefs } from 'vue';
export default {
  setup() {
    const state = reactive({
      visible: true,
      avatarUrl: "https://img12.360buyimg.com/imagetools/jfs/t1/143702/31/16654/116794/5fc6f541Edebf8a57/4138097748889987.png",
      nickName: "test",
    })
    const onChooseAvatar = (e) => {
      const { avatarUrl } = e.detail
      console.log("===== avatarUrl", avatarUrl)
      state.avatarUrl = avatarUrl
    }

    return {
      ...toRefs(state),
      onChooseAvatar
    }
  },
}
</script>

依赖库:

👽 Taro v3.6.2

  Taro CLI 3.6.2 environment info:
    System:
      OS: macOS 11.7
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.19.1 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 8.19.3 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.2 => 3.6.2
      @tarojs/components: 3.6.2 => 3.6.2
      @tarojs/helper: 3.6.2 => 3.6.2
      @tarojs/plugin-framework-vue3: 3.6.2 => 3.6.2
      @tarojs/plugin-html: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-alipay: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-h5: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-jd: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-qq: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-swan: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-tt: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-weapp: 3.6.2 => 3.6.2
      @tarojs/runtime: 3.6.2 => 3.6.2
      @tarojs/shared: 3.6.2 => 3.6.2
      @tarojs/taro: 3.6.2 => 3.6.2
      @tarojs/webpack5-runner: 3.6.2 => 3.6.2
      babel-preset-taro: 3.6.2 => 3.6.2
      eslint-config-taro: 3.6.2 => 3.6.2
vvppvyoh

vvppvyoh5#

同样问题 我taro版本是3.6.2,但是获取不到微信头像

<template>
  <view class="index">
    <button class="avatar-wrapper" open-type="chooseAvatar" onChooseAvatar="onChooseAvatar">
      <img class="avatar" src="{{avatarUrl}}" />
    </button>
    <input type="nickname" class="weui-input" placeholder="请输入昵称" v-model="nickName" />
  </view>
</template>

<script>
import { reactive, toRefs } from 'vue';
export default {
  setup() {
    const state = reactive({
      visible: true,
      avatarUrl: "https://img12.360buyimg.com/imagetools/jfs/t1/143702/31/16654/116794/5fc6f541Edebf8a57/4138097748889987.png",
      nickName: "test",
    })
    const onChooseAvatar = (e) => {
      const { avatarUrl } = e.detail
      console.log("===== avatarUrl", avatarUrl)
      state.avatarUrl = avatarUrl
    }

    return {
      ...toRefs(state),
      onChooseAvatar
    }
  },
}
</script>

依赖库:

👽 Taro v3.6.2

  Taro CLI 3.6.2 environment info:
    System:
      OS: macOS 11.7
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.19.1 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 8.19.3 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.2 => 3.6.2
      @tarojs/components: 3.6.2 => 3.6.2
      @tarojs/helper: 3.6.2 => 3.6.2
      @tarojs/plugin-framework-vue3: 3.6.2 => 3.6.2
      @tarojs/plugin-html: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-alipay: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-h5: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-jd: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-qq: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-swan: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-tt: 3.6.2 => 3.6.2
      @tarojs/plugin-platform-weapp: 3.6.2 => 3.6.2
      @tarojs/runtime: 3.6.2 => 3.6.2
      @tarojs/shared: 3.6.2 => 3.6.2
      @tarojs/taro: 3.6.2 => 3.6.2
      @tarojs/webpack5-runner: 3.6.2 => 3.6.2
      babel-preset-taro: 3.6.2 => 3.6.2
      eslint-config-taro: 3.6.2 => 3.6.2

我的3.6.6也是,有解决的方法吗?

rnmwe5a2

rnmwe5a26#

啥时候回收的,没看到消息呀,有微信的通知link么

ui7jx7zq

ui7jx7zq7#

啥时候回收的,没看到消息呀,有微信的通知link么
https://developers.weixin.qq.com/community/develop/doc/00022c683e8a80b29bed2142b56c01

自 2022 年 10 月 25 日 24 时后(以下统称 “生效期” ),用户头像昵称获取规则将进行如下调整:

自生效期起,小程序 wx.getUserProfile 接口将被收回:生效期后发布的小程序新版本,通过 wx.getUserProfile 接口获取用户头像将统一返回默认 灰色头像 ,昵称将统一返回 “微信用户”。生效期前发布的小程序版本不受影响,但如果要进行版本更新则需要进行适配。
自生效期起,插件通过 wx.getUserInfo 接口获取用户昵称头像将被收回:生效期后发布的插件新版本,通过 wx.getUserInfo 接口获取用户头像将统一返回默认 灰色头像 ,昵称将统一返回 “微信用户”。生效期前发布的插件版本不受影响,但如果要进行版本更新则需要进行适配。通过 wx.login 与 wx.getUserInfo 接口获取 openId、unionId 能力不受影响。

juzqafwq

juzqafwq8#

同样问题 我taro版本是3.6.2,但是获取不到微信头像

<template>
  <view class="index">
    <button class="avatar-wrapper" open-type="chooseAvatar" onChooseAvatar="onChooseAvatar">
      <img class="avatar" src="{{avatarUrl}}" />
    </button>
    <input type="nickname" class="weui-input" placeholder="请输入昵称" v-model="nickName" />
  </view>
</template>

<script>
import { reactive, toRefs } from 'vue';
export default {
  setup() {
    const state = reactive({
      visible: true,
      avatarUrl: "https://img12.360buyimg.com/imagetools/jfs/t1/143702/31/16654/116794/5fc6f541Edebf8a57/4138097748889987.png",
      nickName: "test",
    })
    const onChooseAvatar = (e) => {
      const { avatarUrl } = e.detail
      console.log("===== avatarUrl", avatarUrl)
      state.avatarUrl = avatarUrl
    }

    return {
      ...toRefs(state),
      onChooseAvatar
    }
  },
}
</script>


依赖库: ``` 👽 Taro v3.6.2

Taro CLI 3.6.2 environment info:
System:
OS: macOS 11.7
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.19.3 - /usr/local/bin/npm
npmPackages:
@tarojs/cli: 3.6.2 => 3.6.2
@tarojs/components: 3.6.2 => 3.6.2
@tarojs/helper: 3.6.2 => 3.6.2
@tarojs/plugin-framework-vue3: 3.6.2 => 3.6.2
@tarojs/plugin-html: 3.6.2 => 3.6.2
@tarojs/plugin-platform-alipay: 3.6.2 => 3.6.2
@tarojs/plugin-platform-h5: 3.6.2 => 3.6.2
@tarojs/plugin-platform-jd: 3.6.2 => 3.6.2
@tarojs/plugin-platform-qq: 3.6.2 => 3.6.2
@tarojs/plugin-platform-swan: 3.6.2 => 3.6.2
@tarojs/plugin-platform-tt: 3.6.2 => 3.6.2
@tarojs/plugin-platform-weapp: 3.6.2 => 3.6.2
@tarojs/runtime: 3.6.2 => 3.6.2
@tarojs/shared: 3.6.2 => 3.6.2
@tarojs/taro: 3.6.2 => 3.6.2
@tarojs/webpack5-runner: 3.6.2 => 3.6.2
babel-preset-taro: 3.6.2 => 3.6.2
eslint-config-taro: 3.6.2 => 3.6.2

我的3.6.6也是,有解决的方法吗?
你写错了。 vue的写法是和小程序一致。不能带on. on是react才有的。 这样写就没问题了
<button open-type="chooseAvatar" @chooseAvatar="onChooseAvatar" size="mini" class="btn-avatar">

相关问题