简单操作
# 复制
如下代码,v-as-copy表示复制文本指令,其可以传入一个字符串类型的变量。传入的字符串变量就是要复制的内容。
<template>
<div class="t-copy-area">
<button v-as-copy="text">复制</button>
</div>
</template>
<script>
export default {
name: "t-copy",
data () {
return {
text: '这是一条复制文本(测试版本)'
}
}
}
</script>
<style>
.t-copy-area{
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
}
.t-copy-area>button{
background-color: dodgerblue;
border-radius: 3px;
width: 100px;
height: 40px;
outline: none;
border: none;
color: #ffffff;
}
</style>
Expand Copy Copy
# 拖拽
如下代码,v-as-drag表示拖拽指令,可以拖拽设置了该指令的元素在相应范围内移动。(注意:该指令适用于pc端)
<template>
<div class="t-drag-area">
<button class="drag-btn" v-as-drag>拖拽</button>
</div>
</template>
<script>
export default {
name: "t-drag",
}
</script>
<style>
.t-drag-area{
width: 100%;
height: 500px;
box-sizing: border-box;
border-radius: 5px;
position: relative;
background-color: antiquewhite;
}
@media screen and (max-width: 480px) {
.t-drag-area{
height: 250px;
}
}
.t-drag-area .drag-btn{
background-color: dodgerblue;
border-radius: 3px;
width: 100px;
height: 40px;
outline: none;
border: none;
color: #ffffff;
box-sizing: border-box;
position: absolute;
left: 50px;
top: 50px;
}
</style>
Expand Copy Copy
# 长按
如下代码,v-as-longpress表示长按指令,可以对其传入一个回调方法,在方法中执行想要的操作。如下长按后会弹框相应弹框。(注意:该指令适用于pc端)
<template>
<div class="t-long-press-area">
<button v-as-longpress="handleLongpress">长按</button>
</div>
</template>
<script>
export default {
name: "t-long-press",
methods: {
handleLongpress() {
alert('这是长按指令')
}
}
}
</script>
<style>
.t-long-press-area{
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
}
.t-long-press-area>button{
background-color: dodgerblue;
border-radius: 3px;
width: 100px;
height: 40px;
outline: none;
border: none;
color: #ffffff;
}
</style>
Expand Copy Copy
# 回到顶部
v-as-backtop表示回到顶部指令,不需要对其传参数。如下,有两个按钮,点击第一个按钮显示"回到顶部的元素"(该元素会出现在右下角区域,是一个蓝色的按钮),点击第二个按钮隐藏"回到顶部的元素"。点击回到顶部元素可观察到滚动条回到顶部。
<template>
<div class="t-backtop-area">
<button @click="showBacktop" class="show-btn">显示回到顶部元素</button>
<button @click="hideBacktop" class="hide-btn">隐藏回到顶部元素</button>
<img class="backtop-btn" v-show="BacktopVisible" v-as-backtop :src="require('../images/backtop.png')"/>
</div>
</template>
<script>
export default {
name: "t-backtop",
data(){
return{
BacktopVisible:false,
}
},
methods:{
showBacktop(){
console.log(111)
this.BacktopVisible=true;
},
hideBacktop(){
this.BacktopVisible=false;
},
}
}
</script>
<style>
.t-backtop-area {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
}
.t-backtop-area>button{
background-color: dodgerblue;
border-radius: 3px;
width: 150px;
height: 40px;
outline: none;
border: none;
color: #ffffff;
}
.t-backtop-area>.hide-btn{
margin-left: 30px;
}
.t-backtop-area .backtop-btn{
background-color: dodgerblue;
border-radius: 3px;
width: 50px;
height: 50px;
line-height: 50px;
text-align: center;
outline: none;
border: none;
color: #ffffff;
box-sizing: border-box;
position: fixed;
right: 30px;
bottom: 30px;
z-index: 2000;
}
</style>
Expand Copy Copy