js | execCommand 複製

copy(val) {
  try {
    // textarea爲帶格式複製,input爲不帶格式複製
    const input = document.createElement("textarea");
    input.value = val; 
    document.body.appendChild(input); 
    input.select(); 
       if (document.execCommand('Copy')) this.$message.success('複製成功');
       else { this.$message.error('複製失敗'); }
       document.body.removeChild(input);   
  } catch (err) {
    this.$message.error('error');
  }
},

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章