1、安装
npm install --save vue-clipboard2
2、main.js
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
3、页面使用
<template>
<view class="copyBox">
<view class="copyLeft">
充值订单号:<text :value='coptValue'>{{ coptValue }}</text>
</view>
<view class="copyRight" @tap="copy">
<image src="../../static/images/copy.png" />
</view>
</view>
</template>
<script>
export default {
data() {
return {
coptValue: '1324567812346578', // 复制的值
}
},
methods: {
// 复制文本
copy() {
this.$copyText(this.coptValue).then(
res => {
uni.showToast({
title: '复制成功',
icon: 'none'
})
}
)
},
}
}
</script>
<style lang="less">
.copyBox {
width: 90%;
margin: 0 auto;
padding: 24rpx 0;
background: #fff;
display: flex;
justify-content: space-between;
font-size: 28rpx;
color: #A0A0A0;
box-shadow: 0 0 12rpx #e4e3e3;
border-radius: 16rpx;
.copyLeft {
padding-left: 30rpx;
}
text {
color: #000000;
}
.copyRight {
width: 42rpx;
height: 42rpx;
padding-right: 30rpx;
image {
width: 100%;
height: 100%;
}
}
}
</style>