记录项目中遇到,点击分享复制当前页面链接功能
html部分
<view class="u-flex u-p-l-80" @tap="copy">
<uni-icons type="upload" :size="14"></uni-icons>
<view class="font-24 c-666 font-B u-p-l-10">分享人数:{{goods.sharePeople || 0}}</view>
</view>
方法部分
methods: {
//分享复制链接
copy(code) {
var pages = getCurrentPages() // 获取栈实例
let domain = 'http://xxxxxx.com/'//项目的域名
let currentRoute = pages[pages.length-1].route; // 获取当前页面路由
let currentPage = domain + pages[pages.length-1]['$page']['fullPath'] //当前页面路径(带参数)
uni.setClipboardData({
data: currentPage,
success: () => {
setTimeout(()=>{
uni.showToast({
title: '已复制到粘贴板',
icon: 'none'
});
})
}
});
uni.hideToast();
},
}
用到uniapp原生的api uni.setClipboardData()
菜鸟用作记录用