vue中点击按钮实现复制 vue-clipboard2

news/2024/7/10 1:45:09 标签: vue, 复制到剪贴板, VueClipboard
npm install --save vue-clipboard2

首先先安装并引入:

import Vue from 'vue'

import VueClipboard from 'vue-clipboard2';//引入复制功能插件

Vue.use(VueClipboard);

html部分:

<input v-model="shareUrl" disabled="disabled">

<button type="button"  v-clipboard:copy="shareUrl" v-clipboard:success="onCopy" v-clipboard:error="onError">复制</button>

js部分:

data中加入要复制的那个变量

shareUrl:'',

methods中加入

    onCopy:function(){

      //alert("复制成功")

    },

    onError:function(){

      alert("复制失败")

    },


http://www.niftyadmin.cn/n/797813.html

相关文章

css全屏变灰色(特殊节日使用)

效果图&#xff1a; body上增加class“filter”后 使用滤镜filter的grayscale函数。 <style> .filter { -webkit-filter: grayscale(100%); /* webkit */ -moz-filter: grayscale(100%); /*firefox*/ -ms-filter: grayscale(100%); /*ie9*/ -o-filter: grayscal…

flex的一种常用布局实现

1.有些页面的内容较少&#xff0c;撑不起整个屏幕&#xff0c;结果底部内容显示在了屏幕中间位置。 2.中间部分实现圣杯布局 效果图&#xff1a; 代码&#xff1a; 主要使用了flex:1; <html> <head> <meta charset"utf-8"/> <title…

layui下的table获取选中行数据

静态html&#xff1a; <table lay-filter"goods-table" id"goods-table" class"table-list my-table-list" cellspacing"0" cellpadding"0" style"display: none;"> <thead> …

小程序自定义导航栏

记录下大神写的导航栏组件 源自&#xff1a;https://juejin.im/post/5d557e2e5188255af1619716 小程序改组件的下载链接&#xff1a;https://github.com/lingxiaoyi/miniprograms-navigation-bar

shell编程之数组篇

#!/bin/bash :<<EOF 数组中可以存放多个值。Bash Shell 只支持一维数组&#xff08;不支持多维数组&#xff09;&#xff0c;初始化时不需要定义数组大小&#xff08;与 PHP 类似&#xff09;。与大部分编程语言类似&#xff0c;数组元素的下标由0开始 EOF #格式 元素用…

art.dialog窗体之间传值

父页面 //添加商品 var data; function changeGoods(index){ var brandId$("#brandId").val(); parent.art.dialog.open(/replenishment/toAddGoods, { title: 选择商品, width:1200, height:600…

layui 隐藏table的某一列

html部分&#xff1a; <table lay-filter"goods-table" id"goods-table" class"table-list my-table-list" cellspacing"0" cellpadding"0" style"display: none;"> <thead> …

shell编程之流程控制篇

#!/bin/bash #if elif fi #如果else分支没有语句执行&#xff0c;就不要写这个else。 #格式 #if condition #then # command1 # command2 # ..... # commandn #elif condition2 #then # commandn #else # commandm #fi#也可以写成一行,例如 #if [ $(ps -ef | gre…