[Vue] Vue mobile terminal h5 web page writes the mobile phone clipboard content, vue-clipboard2 plug-in one-click copy actual combat

Project scenario:

提示:这里简述项目相关背景:

Vue mobile terminal project, open the webpage on the mobile terminal, copy the specified content variable with one click

Reference link 1


Problem Description

提示:这里描述项目中遇到的问题:

copy copy, copy variable to clipboard


solution:

1. Download the plug-in

npm install vue-clipboard2 --save

2. Introduction

在main.js中引入

import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

3, used in the method

Dialog.alert({
    
    
	title: '请复制链接到浏览器下载',
	message: "你的链接",
	confirmButtonText: "一键复制"
}).then(() => {
    
    
	this.$copyText("你要写入剪贴板的内容").then((e) => {
    
    
			Toast('链接复制成功');
		}, (e) => {
    
    
			Toast('链接复制失败');
		});
	});

Variables can be used and can be written anywhere in the methods method.

The case is as follows

insert image description here
The selected one is what you write to the clipboard

let u = navigator.userAgent; // 获取手机型号
let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

Determine the device model.

Guess you like

Origin blog.csdn.net/qq_51055690/article/details/128465846