weChat小程序--点击事件复制data绑定参数

index.wxml

 <view class="card_text sub" bindtap="onCallPhoneTap" data-name="12345678911">手机:12345678911</view>

  <view class="card_text" catchtap='onCopyTap' data-name="12345678911">微信:12345678911</view>
  <view class="card_text sub" catchtap='onCopyTap' data-name="12345678911"><text style='margin-right:14rpx;'>QQ</text>:12345678911</view>
  <view class="card_text">地址:火星</view>

点击触发绑定事件onCallPhoneTap~拨打电话/onCopyTap 剪切板

index.js

/**
* 拨打电话
*/
onCallPhoneTap: function (e) {
    const dataset = e.currentTarget.dataset, value = dataset.name;
    console.log(e)
		wx.makePhoneCall({
			// phoneNumber: this.data.tel,
			phoneNumber: value,
		});
	},

	/**
	 * 复制信息
	 */
	onCopyTap: function (e) {
		const dataset = e.currentTarget.dataset, value = dataset.name;
		wx.setClipboardData({
			data: value,
			success: function (res) {
				wx.showToast({ title: '复制成功!' });
			}
		});
	},
注:绑定信息数据在  e.currentTarget.dataset  中,data-name对应为e.currentTarget.dataset.name,即可获取

猜你喜欢

转载自blog.csdn.net/h330531987/article/details/80372724