|
@@ -8,10 +8,17 @@
|
|
|
<div v-else class="">
|
|
|
<span>当前环境不支持 window.navigator.clipboard</span>
|
|
|
</div>
|
|
|
+ <div class="">
|
|
|
+ <div class="">copy-to-clipboard</div>
|
|
|
+ <v-btn @click="syncCopy()">同步写入剪贴板</v-btn>
|
|
|
+ <v-btn @click="asyncCopy()">异步写入剪贴板</v-btn>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import copy from 'copy-to-clipboard';
|
|
|
+
|
|
|
export default {
|
|
|
auth: false,
|
|
|
data() {
|
|
@@ -40,6 +47,35 @@ export default {
|
|
|
this.$toast.error(`读取失败 ${error.message}`);
|
|
|
}
|
|
|
},
|
|
|
+ syncCopy() {
|
|
|
+ try {
|
|
|
+ const now = Date.now();
|
|
|
+ const res = copy(now, {
|
|
|
+ debug: true,
|
|
|
+ message: 'Press #{key} to copy',
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!res) throw new Error('写入失败');
|
|
|
+ this.$toast.success(`写入成功 ${now}`);
|
|
|
+ } catch (error) {
|
|
|
+ this.$toast.error(`写入失败 ${error.message}`);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async asyncCopy() {
|
|
|
+ try {
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
+ const now = Date.now();
|
|
|
+ const res = copy(now, {
|
|
|
+ debug: true,
|
|
|
+ message: 'Press #{key} to copy',
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!res) throw new Error('写入失败');
|
|
|
+ this.$toast.success(`写入成功 ${now}`);
|
|
|
+ } catch (error) {
|
|
|
+ this.$toast.error(`写入失败 ${error.message}`);
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|