VueUse实用工具
1.安装
npm i @vueuse/core
2.使用
- useClipboard 剪贴板
<script setup lang="ts">
import { ref } from 'vue'
import { useClipboard, usePermission } from '@vueuse/core' const input = ref('')
const { text, isSupported, copy } = useClipboard()
const permissionRead = usePermission('clipboard-read')
const permissionWrite = usePermission('clipboard-write')
</script> <template>
<div v-if="isSupported">
<el-input v-model="input" type="text"></el-input>
<el-button @click="copy(input)">复制</el-button>
</div>
<p v-else>
该浏览器不支持useClipboard剪贴板API
</p>
</template>
- useFullscreen 全屏
<script setup lang="ts">
import { ref } from 'vue'
import { useFullscreen } from '@vueuse/core' const el = ref(null)
const { toggle, isFullscreen } = useFullscreen(el)
</script> <template>
<el-button v-if="!isFullscreen" @click="toggle">全屏</el-button><br>
<el-button v-if="isFullscreen" @click="toggle">退出全屏</el-button>
</div>
</template>
- useNow 获取当前时间
<script setup lang="ts">
import { useNow } from '@vueuse/core' const now = useNow()
</script> <template>
<div>Now: {{ now }}</div>
</template>
- useDateFormat 格式化时间
<script setup lang="ts">
import { ref, computed } from 'vue-demi'
import { useNow, useDateFormat } from '@vueuse/core' const formatted = useDateFormat(useNow(), 'YYYY-MM-DD HH:mm:ss')
</script> <template>
<div>{{ formatted }}</div>
</template>
- useBase64
<script setup lang="ts">
import type { Ref } from 'vue'
import { ref } from 'vue'
import { useBase64 } from '@vueuse/core' const text = ref('')
const file = ref() as Ref<File>
const image = ref() as Ref<HTMLImageElement> const { base64: textBase64 } = useBase64(text)
const { base64: fileBase64 } = useBase64(file)
const { base64: imageBase64 } = useBase64(image)
const { base64: bufferBase64 } = useBase64(new ArrayBuffer(8)) function onFileInput(e: Event) {
file.value = (e.target as HTMLInputElement).files![0]
}
</script> <template>
<div space-y-4>
<div grid md:grid-cols-2 gap-2>
<div>
<span>Text Input</span>
<textarea v-model="text" h-40 type="text" placeholder="Type something..." />
</div>
<div>
<span>Base64</span>
<textarea h-40 :value="textBase64" readonly />
</div>
</div> <div grid md:grid-cols-2 gap-2>
<div>
<span>Buffer Input</span>
<pre mt-2>new ArrayBuffer(1024)</pre>
</div>
<div>
<span>Base64</span>
<textarea h-40 :value="bufferBase64" readonly />
</div>
</div> <div grid md:grid-cols-2 gap-2>
<div>
<span>File Input</span>
<div>
<input mt-2 type="file" @input="onFileInput">
</div>
</div>
<div>
<span>Base64</span>
<textarea h-40 :value="fileBase64" readonly />
</div>
</div> <div grid md:grid-cols-2 gap-2>
<div>
<span>Image Input</span>
<img
ref="image"
w-full h-40 object-cover
class="rounded mt-2"
src="https://images.unsplash.com/photo-1494256997604-768d1f608cac?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=200&q=80"
>
</div>
<div>
<span>Base64</span>
<textarea h-40 :value="imageBase64" readonly />
</div>
</div>
</div>
</template> <style scoped>
textarea {
min-width: 0px !important;
width: 100%;
}
</style>
VueUse实用工具的更多相关文章
- Bootstrap<基础十> 响应式实用工具
Bootstrap 提供了一些辅助类,以便更快地实现对移动设备友好的开发.这些可以通过媒体查询结合大型.小型和中型设备,实现内容对设备的显示和隐藏. 需要谨慎使用这些工具,避免在同一个站点创建完全不同 ...
- 10款让WEB前端开发人员更轻松的实用工具
这篇文章介绍10款让Web前端开发人员生活更轻松的实用工具.每个Web开发人员都有自己的工具箱,这样工作中碰到的每个问题都有一个好的解决方案供选择. 对于每一项工作,开发人员需要特定的辅助工具,所以如 ...
- 十款让 Web 前端开发人员更轻松的实用工具
这篇文章介绍十款让 Web 前端开发人员生活更轻松的实用工具.每个 Web 开发人员都有自己的工具箱,这样工作中碰到的每个问题都有一个好的解决方案供选择. 对于每一项工作,开发人员需要特定的辅助工具, ...
- .Net 高效开发之不可错过的实用工具(转)
.Net 高效开发之不可错过的实用工具(转) 本文摘自: http://www.cnblogs.com/powertoolsteam/p/5240908.html#3372237 Visual Stu ...
- 实用工具推荐(Live Writer)(2015年05月26日)
1.写博客的实用工具 推荐软件:Live Writer 使用步骤: 1.安装 Live Essential 2011,下载地址:http://explore.live.com/windows-live ...
- 快速访问WCF服务--ServiceModel 元数据实用工具 (Svcutil.exe)
基本定义 ServiceModel 元数据实用工具用于依据元数据文档生成服务模型代码,以及依据服务模型代码生成元数据文档. SvcUtil.exe ServiceModel 元数据实用工具可在 Win ...
- Mac开发者必备实用工具推荐
最近一个师兄给我推荐了一些Mac上的实用工具,用起来非常顺手,能提高不少开发效率.于是就想着把自己之前用过的其他工具也整理一下,一块推荐给大家,希望能对大家有帮助. Alfred 目前Mac下最好用的 ...
- SQL cmd 实用工具学习 -1
启动 sqlcmd 实用工具并连接到 SQL Server 的默认实例 在"开始"菜单上,单击"运行". 在"打开"框中,键入 cmd,然后 ...
- 每位iOS开发人员不容错过的10大实用工具
内容简介 1.iOS简介 2.iOS开发十大实用工具之开发环境 3.iOS开发十大实用工具之图标设计 4.iOS开发十大实用工具之原型设计 5.iOS开发十大实用工具之演示工具 6.iOS开发十大实用 ...
- 【转】十款让 Web 前端开发人员更轻松的实用工具
这篇文章介绍十款让 Web 前端开发人员生活更轻松的实用工具.每个 Web 开发人员都有自己的工具箱,这样工作中碰到的每个问题都有一个好的解决方案供选择. 对于每一项工作,开发人员需要特定的辅助工具, ...
随机推荐
- laravel常用集合的使用
创建集合: //数组1 $connection = collect([ ['name'=>'jack','age'=>'18','email'=>'ceshi@qq.com'], [ ...
- [NOIP1999 提高组] 旅行家的预算
洛咕 题意:一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离 \(D_1\).汽车油箱的容量 \(C\)(以升为单位).每升汽油能行驶的距离 \( ...
- 统计 nginx access.log
awk '{print $1}' access22.log | sort | uniq -c | sort -nr -k1
- 原创分享 HubbleDotNet 最新绿色版,服务端免安装,基于eaglet 最后V1.2.8.9版本开发,bug修正,支持一键生成同步表
HubbleDotNet 是一个基于.net framework 的开源免费的全文搜索数据库组件.开源协议是 Apache 2.0.HubbleDotNet提供了基于SQL的全文检索接口,使用者只需会 ...
- OPENCV3 API
图像翻转 void flip(InputArray src, OutputArray dst, int flipCode); flipCode: 0: x 轴翻转 1: y 轴翻转 <0: x, ...
- ubuntu18 build opencv4 from source
1 安装依赖 ## Install dependencies sudo apt -y install build-essential checkinstall cmake pkg-config yas ...
- 查询openmp的版本
vim test.cpp #include <unordered_map>#include <cstdio>#include <omp.h> int main(in ...
- SSH反向隧道实现内网穿透
1.客户端配置 /home/tsingyundev/zyy bind209.sh内容 ssh -fCNL *:1234:localhost:10022 localhost ssh209.sh内容 ss ...
- 面试视频知识点整理1-7(http协议)
http协议类 1)http协议的主要特点 简单快速 统一资源符 灵活 通过http协议,可以修改http头,完成不同数据类型的传输 无连接 ...
- js 操作(数字前端去0、文字去除空格、截取字符串、保留几位小数、数字不足位数前补0)
1.数字前端去0 var num = number.replace(/\b(0+)/gi,"") 2.文字去除空格 var str = str.replace(/(^\s*)|(\ ...