1 Star 0 Fork 50

zd86 / avue-doc

forked from smallwei / avue-doc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
clipboard.md 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
smallwei 提交于 2020-05-30 20:51 . init docs
<script> export default { data() { return { text: '', textarea: '' } }, methods: { copyText() { this.$Clipboard({ text: this.text }).then(() => { this.$message.success('复制成功') }).catch(() => { this.$message.error('复制失败') }); }, copy() { this.$Clipboard({ text: '测试==复制至剪切板的文本==测试' }).then(() => { this.$message.success('复制成功') }).catch(() => { this.$message.error('复制失败') }); } } } </script>

Clipboard 复制剪切板

:::tip 1.0.6+ ::::

:::demo

<div style="width:400px">
  <div style="margin-bottom:10px">
    <el-button @click="copy">直接复制</el-button>
    <el-button @click="textarea=''">清 空</el-button>
  </div>
  <el-input placeholder="内容" v-model="text">
    <template slot="append">
      <el-button @click="copyText" color="primary">复制</el-button>
    </template>
  </el-input>
  <div style="margin-top:10px">
    <el-input type="textarea" v-model="textarea" cols="40" rows="3"></el-input>
  </div>
</div>
<script>
export default {
   data() {
      return {
        text: '',
        textarea: ''
      }
    },
    methods: {
      copyText() {
        this.$Clipboard({
          text: this.text
        }).then(() => {
          this.$message.success('复制成功')
        }).catch(() => {
          this.$message.error('复制失败')
        });
      },
      copy() {
        this.$Clipboard({
          text: '测试==复制至剪切板的文本==测试'
        }).then(() => {
          this.$message.success('复制成功')
        }).catch(() => {
          this.$message.error('复制失败')
        });
      }
    }
}
</script>

:::

Variables

参数 说明 类型 可选值 默认值
text 复制的文本 String - -
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/86zhangdong/avue-doc.git
git@gitee.com:86zhangdong/avue-doc.git
86zhangdong
avue-doc
avue-doc
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891