当前位置: 首页 > news >正文

vue naive ui 按钮绑定按键

使用vue (naive ui) 绑定Enter 按键

知识点:

  • 按键绑定Button
  • 全局挂载使得message,notification, dialog, loadingBar 等NaiveUI 生效
  • UMD方式使用vue 与 naive ui
  • 将vue默认的 分隔符大括号 替换 为 [[ ]]
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>按钮绑定按键</title><script src="https://unpkg.com/vue@3.3.4/dist/vue.global.js"></script><script src="https://unpkg.com/naive-ui@2.34.4/dist/index.js"></script><link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"></head>
<body><div id="app"><n-button @click="compareClick" id="myButton">[[ button_name ]]</n-button></div><script>console.log("start")const disabledRef = Vue.ref(true);// message,notification, dialog, loadingBar 等生效的方法const {message, notification, dialog, loadingBar} = naive.createDiscreteApi(["message", "dialog", "notification", "loadingBar"],{configProviderProps: naive.configProviderPropsRef});const App = {setup() {document.onkeyup = function (e) {if (e.key == 'Enter') {var myButton = document.getElementById("myButton");message.info("您使用按键Enter触发了按钮,请稍后",{keepAliveOnHover: true});myButton.click()}}return {button_name: 'Button',compareClick() {loadingBar.start();disabledRef.value = false;message.info("您已经点击了按钮,请稍后",{keepAliveOnHover: true});var timeInterval = 2000;setTimeout(() => {loadingBar.finish();disabledRef.value = true;}, timeInterval);}}}}// 将 默认的 分隔符大括号 替换 为 [[ ]]App.delimiters = ["[[", "]]"];const app = Vue.createApp(App)console.log("App.createApp ")app.use(naive)console.log("use naive")app.mount('#app')console.log("mount")
</script>
</body>
</html>

Enter 触发按钮

在这里插入图片描述

点击触发按钮

在这里插入图片描述

参考链接

  • https://juejin.cn/post/7188032240775856185
  • https://www.naiveui.com/zh-CN/os-theme/components/discrete
http://www.lryc.cn/news/145302.html

相关文章:

  • Viobot基本功能使用及介绍
  • 《PMBOK指南》第七版12大原则和8大绩效域
  • docker 启动命令
  • C++ DAY7
  • Vue2 使用插件 Volar 报错:<template v-for> key should be placed on the <template> tag.
  • 启动线程方法 start ()和 run ()有什么区别
  • Java的全排列模板
  • 读书笔记——《万物有灵》
  • 面试现场表现:展示你的编程能力和沟通技巧
  • 34亿的mysql表如何优雅的扩字段长度兵并归档重建
  • C#_进程单例模式.秒懂Mutex
  • AcWing 5050. 排序 (每日一题)
  • 【TypeScript】proxy 和 Reflect
  • STM32f103入门(5)定时器中断
  • Mybatis查询数据
  • 【前车之鉴】: 2023最新教程-将java程序打包到maven私服的正确打开方式,详细流程介绍不怕你掌握不了
  • 如何理解IaaS、PaaS、SaaS?盘点受欢迎的八大SaaS平台!
  • 立创EDA专业版的原理图上器件有一个虚线框
  • JUC并发编程--------基础篇
  • 秒懂算法2
  • 隐秘的角落:Java连接Oracle提示Connection timed out
  • 基于微信小程序的餐厅预订系统的设计与实现(论文+源码)_kaic
  • 科技政策 | 四川省科学技术厅关于发布2024年第一批省级科技计划项目申报指南的通知
  • 深入了解Webpack:特性、特点和结合JS混淆加密的实例
  • 2023-08-23力扣每日一题
  • 分发饼干【贪心算法】
  • 为什么网络互联地址设置为30位地址
  • 青少年棒球锦标赛发展·棒球1号位
  • Unity实现UI图片面板滚动播放效果第二弹
  • Redis的基本操作