vue 點擊按鈕複製input內容

方法:

例子: 複製 numbers 的值到剪切板

    <el-col :span="20" >
      <el-form-item label="服務器ID" label-width="120px">
        {{numbers}} 
       </el-form-item>
     </el-col>
     <el-col :span="4" align="center">
       <el-button type="primary" size="small" @click="fuzhi1">複製</el-button>
     </el-col>
fuzhi1(){
    var input = document.createElement("input");   // 直接構建input
    input.value = this.numbers;  // 設置內容 需要複製的內容
    document.body.appendChild(input);    // 添加臨時實例
    input.select();   // 選擇實例內容
    document.execCommand("Copy");   // 執行復制
    document.body.removeChild(input); // 刪除臨時實例
    alert("鏈接已複製成功")
    // this.$message({   // 這裏提示語
   //     message: "鏈接已複製成功",
   //     type: 'warning'
    // });
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章