does not have a method "getUserProfile" to handle event "tap".
uniapp [uview]:<button class="login-title" bindtap="getUserProfile">获取昵称和头像</button>
无法出发弹窗,显示 does not have a method "getUserProfile" to handle event "tap". 函数妈名字确认是有的
代码:
```
<template>
<view class="wrap cell-page">
<view class="user-area" v-show="userInfo.uid != 0">
<u-row justify="space-between" customStyle="margin-bottom: 10px">
<u-col span="7">
<view class="u-page__login">
<view class="login-title">欢迎回来 {{userInfo.phoneNumber}} </view>
</view>
</u-col>
<u-col span="3">
<view class="u-demo-block">
<text class="u-demo-block__title">{{ userInfo.nickname }}</text>
<view class="u-demo-block__content">
<view class="u-page__image-item">
<u--image shape="circle" :src="userInfo.avatarUrl" width="80px" height="80px"></u--image>
</view>
</view>
</view>
</u-col>
</u-row>
</view>
<view class="login-area" v-show="userInfo.uid == 0">
<!-- #ifdef MP-WEIXIN -->
<u-row justify="space-between" customStyle="margin-bottom: 10px">
<u-col span="7">
<view class="u-page__login">
<view>
<button class="login-title" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信一键登录</button>
<view class="login-text">登陆后可享受更多功能</view>
</view>
</view>
</u-col>
<u-col span="3">
<view class="u-demo-block">
<text class="u-demo-block__title">昵称</text>
<view class="u-demo-block__content">
<view class="u-page__image-item">
<u--image shape="circle" :src="userInfo.avatarUrl" width="80px" height="80px"></u--image>
</view>
</view>
</view>
</u-col>
</u-row>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<u-row justify="space-between" customStyle="margin-bottom: 10px">
<u-col span="7">
<view class="u-page__login" @click="openPopup()">
<view>
<button class="login-title">登录/注册 2</button>
<view class="login-text">登陆后可享受更多功能</view>
</view>
</view>
</u-col>
<u-col span="3"></u-col>
</u-row>
<!-- #endif -->
</view>
<button class="login-title" bindtap="getUserProfile">获取用户头像和昵称</button>
<u-popup :safeAreaInsetBottom="true" :safeAreaInsetTop="true" :mode="popupData.mode" :show="popupShow"
:round="popupData.round" :overlay="popupData.overlay" :borderRadius="popupData.borderRadius"
:closeable="popupData.closeable" :closeOnClickOverly="popupData.closeOnClickOverly" @close="close"
@open="open">
<view class="u-popup-slot" :style="{
width: ['bottom', 'top'].includes(popupData.mode) ? '750rpx' : '90%',
marginTop: ['left', 'right'].includes(popupData.mode) ? '480rpx' : '0',
}">
<u-row>
<u-col span="3">
<view class="u-page__popup_item">手机号</view>
</u-col>
<u-col span="5">
<view class="u-page__popup_item">
<u--input v-model="userInfo.phoneNumber" type="number" border="none" placeholder="请填写手机号">
</u--input>
</view>
</u-col>
<u-col span="3"></u-col>
</u-row>
<!-- <u-row>
<u-col span="3">
<view class="u-page__popup_item">验证码</view>
</u-col>
<u-col span="5">
<view class="u-page__popup_item">
<u--input v-model="login_code" border="none" placeholder="请填写验证码"></u--input>
</view>
</u-col>
<u-col span="3">
<view class="u-page__popup_item">
<u-code ref="uCode1" @change="codeChange1" keep-running change-text="倒计时XS"
@start="disabled2 = true" @end="disabled2 = false"></u-code>
<u-button type="primary" @tap="getCode1" :text="tips1" size="small" :disabled="disabled2">
</u-button>
</view>
</u-col>
</u-row> -->
<u-row justify="space-between" customStyle="margin-bottom: 10px">
<view class="u-page__popup_item">
<u-button type="primary" customStyle="margin-top: 10px" text="登录" @click="login_user()">
</u-button>
</view>
</u-row>
</view>
</u-popup>
<!-- 底部导航栏 -->
<view class="u-page__item">
<u-gap height="150"></u-gap>
<u-tabbar :value="indexNavValue" @change="name => indexNavValue = name" :fixed="true" :placeholder="true"
:safeAreaInsetBottom="true">
<u-tabbar-item text="首页" icon="home" :customStyle="myStyle" @click="goPage('/pages/index/index')">
</u-tabbar-item>
<u-tabbar-item text="我的" icon="account" @click="goPage('/pages/user/user')"></u-tabbar-item>
</u-tabbar>
</view>
</view>
</template>
<script>
export default {
data() {
return {
baseUrl: '',
userInfo: {
uid: 0,
unionid: '',
nickname: '',
avatarUrl: 'https://cdn.uviewui.com/uview/album/1.jpg'
},
indexNavValue: 1,
myStyle: {
'border-right': '1px solid #ceccca'
},
popupShow: false,
popupData: {
borderRadius: '',
round: true,
overlay: true,
mode: 'center',
closeable: true,
closeOnClickOverly: true
},
title: '显示关闭按钮',
iconUrl: 'https://cdn.uviewui.com/uview/demo/popup/showCloseBtn.png',
login_code: '',
disabled2: false,
tips1: ''
}
},
methods: {
onShow() {
// #ifdef MP-WEIXIN
uni.login({
provider: 'weixin'
})
// #endif
// 自动登录
this.baseUrl = this.$globals.baseUrl
let uid = uni.getStorageSync('uid')
if (uid != '') {
this.userInfo = Object.assign(this.userInfo, {
uid: uid,
phoneNumber: uni.getStorageSync('phoneNumber'),
nickname: uni.getStorageSync('phoneNumber'),
unionid: uni.getStorageSync('phoneNumber'),
})
console.log(this.userInfo)
} else {
console.log('用户本地缓存为空');
}
},
codeChange1(text) {
this.tips1 = text;
},
getCode1() {
if (this.$refs.uCode1.canGetCode) {
// 模拟向后端请求验证码
uni.showLoading({
title: '正在获取验证码'
})
setTimeout(() => {
uni.hideLoading()
// 这里此提示会被this.start()方法中的提示覆盖
uni.$u.toast('验证码已发送')
// 通知验证码组件内部开始倒计时
this.$refs.uCode1.start()
}, 2000)
} else {
uni.$u.toast('倒计时结束后再发送');
}
},
close() {
this.popupShow = false
},
openPopup() {
console.log('openPopup')
uni.$u.sleep().then(() => {
this.popupShow = !this.show
})
},
//获取手机号
async getPhoneNumber(e) {
let detail = e.detail
let that = this
uni.login({
provider: 'weixin'
}).then((res) => {
console.log('uni.login then')
console.log('data: ', JSON.stringify(res))
if (res[1].errMsg !== 'login:ok') {
console.log('登录失败!' + JSON.stringify(res))
return false
}
//发起网络请求
let code = res[1].code
uni.request({
url: this.baseUrl + 'WxUser/getPhoneNumberLogin', //解密手机号码接口
method: 'POST',
data: {
"code": code,
"encryptedData": detail.encryptedData,
"iv": detail.iv
}
}).then(res => {
console.log('data: ', JSON.stringify(res))
let data = res[1]['data']['data']
console.log('getPhoneNumberLogin then 这里获取手机号', data.phoneNumber)
uni.setStorageSync('phoneNumber', data.phoneNumber)
uni.setStorageSync('nickname', data.nickname)
uni.setStorageSync('uid', data.uid)
uni.setStorageSync('unionid', data.unionid)
let userInfo = {
phoneNumber: data.phoneNumber,
nickname: data.nickname,
uid: data.user_id,
unionid: data.unionid,
}
that.userInfo = userInfo
uni.$u.toast('一键登录成功!')
}).catch(err => {
uni.$u.toast('登录失败,请切换其它登录方式,或重试')
})
})
},
//获取用户信息
getUserProfile(e) {
console.log('用于完善会员资料')
uni.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
console.log('用户昵称为:', JSON.stringify(res.userInfo))
that.userInfo.nickname = res.userInfo.nickName
that.userInfo.avatarUrl = res.userInfo.avatarUrl
that.userInfo.gender = res.userInfo.gender
}
})
},
//登录注册
async login_user() {
if (this.userInfo.phoneNumber.length != 11) {
uni.$u.toast('手机号码是11位')
return
}
uni.request({
url: this.baseUrl + 'WxUser/sampleLogin', //解密手机号码接口
method: 'POST',
data: {
"mobile": this.userInfo.phoneNumber,
}
}).then(res => {
uni.$u.toast('登录成功!')
console.log('res: ', JSON.stringify(res))
let data = res[1]['data']['data']
console.log('code: ', res[1]['data'].code, res[1]['data'].code == 1)
console.log('data: ', JSON.stringify(data))
if (res[1]['data'].code == 1) {
console.log('getPhoneNumberLogin then 这里获取手机号', data.mobile)
uni.setStorageSync('phoneNumber', data.mobile)
uni.setStorageSync('nickname', data.nickname)
uni.setStorageSync('uid', data.user_id)
uni.setStorageSync('unionid', data.unionid)
let userInfo = {
phoneNumber: data.mobile,
nickname: data.nickname,
uid: data.uid,
unionid: data.unionid,
}
this.userInfo = userInfo
uni.$u.toast('登录成功!')
this.close()
} else {
uni.$u.toast('登录失败,请切换其它登录方式,或重试')
}
}).catch(err => {
uni.showToast({
title: '登录失败:' + JSON.stringify(err)
})
})
},
goPage(path) {
uni.navigateTo({
url: path
})
}
}
}
</script>
找到了,把bintap换成@click就好使了,可能uniapp不支持吧
1.你的方法名getUserProfile 是不是写在methods里面的不清楚
2.getUserProfile是不是绑定在bindtap上的不清楚
3.openPopup 干了些啥不清楚
综上,白贴,问题讲不清楚,所以他们很懵逼
贴js代码
Ctrl+F了解一下。
你的js代码里 没有写getUserProfile 方法