使用方法:
1.在父组件中引入"toast.vue"
//import toast from "./toast";

2.在父组件中注册 toast
//components:{toast},

3.放在父组件中使用
//<toast ref="toast"></toast>

4.调用toast组件
//this.$refs.toast.showToast('text')

注:index.vue为父组件,后者为子组件,效果图先上,可以先看是否是自己想要的组件,再选择使用

index.vue

<template>
<div>
<toast ref="toast"></toast>
</div>
</template> <script>
import toast from './toast.vue' export default {
components:{
toast
},
methods:{ },
created(){
this.$refs.toast.showToast('弹出文本TEXT')
}
}
</script> <style lang="less" scoped> </style>

toast.vue

<template>
<div class="toast" v-show="toastShow">
{{toastText}}
</div>
</template> <script>
export default {
data() {
return {
toastShow: false,
toastText: ''
}
},
methods: {
showToast (str) {
let v = this
v.toastText = str
v.toastShow = true
setTimeout(function(){
v.toastShow = false
}, 1500)
}
}
}
</script> <style lang="less" scoped>
.toast {
position: fixed;
z-index: 2000;
left: 50%;
top:45%;
transition:all .5s;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
text-align: center;
border-radius: .1rem;
color:#FFF;
background: rgba(17, 17, 17, 0.7);
padding: .4rem .4rem;
max-width: 14rem;
font-size: .55rem
}
</style>

Vue自行封装常用组件-文本提示的更多相关文章

  1. Vue自行封装常用组件-弹出框

    使用方法: 1.在父组件中引入"box.vue" //import popUpBox from "./box.vue";   2.在父组件中注册 popUpBo ...

  2. Vue自行封装常用组件-倒计时

    倒计时组件,比较复杂一点,大神勿调侃,精确到毫秒,因为项目中多次出现倒计时,所以拿出来分享下 使用方法:1.在父组件中引入"uni-countdown" //import uniC ...

  3. vue移动端常用组件

    3d picker组件 参考链接:https://segmentfault.com/a/1190000007253581?utm_source=tag-newest安装:npm install vue ...

  4. Vue 数组封装和组件data定义为函数一些猜测

     数组封装 var vm={ list:[0,1] } var push=vm.list.push;//把数组原来的方法存起来 vm.list.push=function(arg){//重新定义数组的 ...

  5. Vue文件封装日历组件

    封装就是要具有灵活性,样式自适应,调用的时候传入props就可以变成自己想要的样式. 效果展示网址:https://1963331542.github.io/ 源代码: <template> ...

  6. Vue中封装axios组件实例

    首先要创建一个网络模块network文件夹  里面要写封装好的几个组件 在config.js里面这样写 在index.js要这样写 core.js文件里面内容如下 然后要在main.js文件里面要设置 ...

  7. [ vue ] Quasar封装q-dialog组件,在外层实现弹出框的开启和关闭

    场景描述: 见:https://www.cnblogs.com/remly/p/12981582.html 具体实现: <!-- 父组件 --> <template> < ...

  8. vue中封装swipe组件

    <template> <!-- TODO swipe --> <div id="hy-swiper"> <div class=" ...

  9. VUE 2.0 引入高德地图,自行封装组件

    1. 高德地图官网 申请帐号, 申请相应(JavaScript API)的 Key 2. 在项目中引入, 这里和其他的引入不同的是 直接在 index.html, 不是在 main.js 引入, 博主 ...

随机推荐

  1. Jmeter之Cookie和Session处理

    Jmeter之Cookie和Session处理 1.Cookie 添加方式:线程组-配置元件-HTTP Cookie 管理器,如下图: 2.Session 添加方式:线程组-前置处理器 -HTTP U ...

  2. ansible报错处理

    [root@localhost ~]# ansible testhosts -m command -a 'rm -rf /tmp/haha' [WARNING]: Consider using the ...

  3. strip使用

    strip作用:去掉空格.以及想要去掉的字符,实例如下: In [42]: import subprocess In [42]: output=subprocess.check_output([&qu ...

  4. python操作轻量级数据库

    1.导入Python SQLITE数据库模块 Python2.5之后,内置了SQLite3,成为了内置模块,这给我们省了安装的功夫,只需导入即可~ import sqlite3 2. 创建/打开数据库 ...

  5. BUGKU (Take the maze)

    首先进行查壳,没有壳. 随便输入,看程序执行信息.随意输入字符串,提示key error 放到IDA中打开,在左侧函数窗口中找到main0,F5反编译,进行分析.具体已在分析在图中标识. 关于main ...

  6. java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents...

    出现这个错误的原因是时区有问题,可以在mysql中执行命令: set global time_zone='+8:00'; 如上是修改为北京时间(GMT+0800). 查看修改: show variab ...

  7. 【POJ - 3087】Shuffle'm Up(模拟)

    Shuffle'm Up 直接写中文了 Descriptions: 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12, ...

  8. 【并行计算-CUDA开发】FPGA 设计者应该学习 OpenCL及爱上OpenCL的十个理由

    为什么要学习OpenCL呢?就目前我所从事的医疗超声领域,超声前端的信号处理器一般是通过FPGA或FPGA+DSP来设计的,高端设备用的是FPGA+ GPU架构.传统的设计方法是通过HDL语言来进行设 ...

  9. JS 根据字节 截取字符串函数

    function reBytesStr(str, len) { if ((!str && typeof(str) != 'undefined')) {return '';} var n ...

  10. luoguP1352没有上司的舞会(树形DP)

    题目链接:https://www.luogu.org/problemnew/show/P1352 题意:给定n个结点,每个结点有一个权值,给n-1条边,n个结点构成一棵树.并且规定一个结点的父结点如果 ...