小笔记-常用总结-element $prompt 使用和复制链接

590 阅读1分钟
  1. 复制链接

  handlecopy(url) {
      this.copy_value = url
      console.log(this.copy_value)
      setTimeout(()=>{
        let text = document.getElementById('copy')
        text.select()
        if (document.execCommand('copy')) {
            document.execCommand('copy');
            this.$message('复制成功');
        }
      },100)
      
    }
    

比如 复制当前行的url

2.element ui的 $prompt 使用问题总结

2.1


 this.$prompt("是否禁用CP?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        [row.ceshi? 'inputValue' :'']:row.ceshi,
        inputPlaceholder:"请输入提交原因",
        inputType:"text",
        inputErrorMessage:"提交原因不能为空",
         inputValidator:(value)=>{
           if(!value) {
             return '提交原因不能为空'
           }
         }
      })

inputValue 会触发校验。 可能默认为空的情况。就会一直触发校验红框。为了避免不满足条件的 红框不在出现。则inputValue属性 满足条件 显示。不满足条件这个key值隐藏。

2.2 也可以写为


      inputValue: row.ceshi ||null

inputValue 的value值为空会触发为空校验。但是如果为 null则不会触发 校验 .默认是显示row.ceshi

  inputValue: row.ceshi || undefined

undefined 和 null同理

2.3 第三种办法是

  let config ={
        confirmButtonText: "确定",
        cancelButtonText: "取消",
          inputType:"text",
         inputErrorMessage:"提交原因不能为空",
         inputValidator:(value)=>{
           if(!value) {
             return '提交原因不能为空'
           }
         }
      }
      if(row.cooperationText)  {
        config.inputValue  =row.ceshi
      }

       this.$prompt("是否做此操作?", "提示", config).then((value)=>{
         console.log('输入的内容是'+ value)
       })

这样也可以保证 inputValue 不满足条件的时候不添加。其他属性同理。