秒转换成年月日时分秒 和复制文本到剪贴板

  • 秒转换成年月日时分秒

getDateStr (seconds) {
      let date = new Date(seconds)
      let year = date.getFullYear()
      let month = date.getMonth() + 1
      let day = date.getDate()
      let hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
      let minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
      let second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      let currentTime = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
      return currentTime
    }
getDateStr(1553161922000) // 2019-03-21 17:52:02
  • 复制文本

<el-input :value="`${activityHost}/mobile/activity/join?id=${activityId}`" :readonly="true" ref="activeUrl">
       <template slot="append">
               <el-button type="text" style="padding: 10px 20px;" @click="copyActiveUrl">复制</el-button>
       </template>
</el-input>

copyActiveUrl() {
var activeUrl = this.$refs.activeUrl.$refs.input // 要操作的Dom
activeUrl.select()
document.execCommand("Copy");
}

或者:
<script type="text/javascript">
function copy()
{
  var url=document.getElementById("textID"); // 获取要操作的DOM
  Url2.select(); // 选择对象
  document.execCommand("Copy"); // 执行浏览器复制命令
  alert("已复制好,可贴粘。");
}
</script>
<textarea cols="20" rows="10" id="textID">用户定义的代码区域</textarea>
<input type="button" onClick="copy()" value="点击复制代码" />

猜你喜欢

转载自www.cnblogs.com/linjiu0505/p/10579082.html
今日推荐