每日技术总结:Toast组件,eslint,white-space,animate,$emit

1.一个优雅的提示是网站必不可少的。

请参考:vue2.0 自定义 提示框(Toast)组件

2.ESLint使用总结

(1)在.eslintrc.js里关闭某条规则, ‘规则名‘: ‘off‘或0

举例:

rules: {
    ‘generator-star-spacing‘: ‘off‘,‘no-restricted-syntax‘: ‘off‘,
    ‘indent‘: 0,
    ‘new-cap‘: 0
  }

(2)// eslint-disable-next-line 对下一行禁用,举例代码:

// eslint-disable-next-line
var curType = type ? type : opt.defaultType

(3)// eslint-disable-line 对这一行禁用,举例代码:

toastVM = new toastTpl() // eslint-disable-line

(4)eslint常见规则,请参考: ESLint常见命令(规则表)

3.white-space,word-spacing,letter-spacing,word-break这些都是什么鬼?

参见博客:word-spacing、word-break、letter-spacing和white-space

4.CSS动画库,Animate.css

官方地址:https://daneden.github.io/animate.css/

(1)安装: npm install animate.css --save 或 yarn add animate.css

(2)引入: vue项目,src/main.js 代码如下:

import animate from ‘animate.css‘

Vue.use(animate)

(3)使用:在需要动画的vue文件,比如detail.vue

示例代码:

<transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut" :duration="200">
    <div class="mask" v-show="cartModalShow"></div>
</transition>

注意:

  • animated类名必须加
  • 第二个类名参考官方文档里面的动画名,如bounceIn,fadeOut,slideOutUp……
  • <transition>里面的元素必须是单独的,没有兄弟元素的。并且是有v-show,v-if,等显示和隐藏相关的指令的。。

5.$emit()

需求情景描述:我在详情页(父组件)点‘加入购物车’按钮,显示购物车信息模态框(子组件),在模态框里点‘继续购物’关闭该模态框,模态框的显示和隐藏是父组件的一个参数cartModalShow控制的。

也就是说,点击事件发生在子组件,需要控制父组件里的某个参数。怎么办吧?

代码示例:

这是子组件:

<template>
  <div class="cart-modal">
    <div class="msg">加入购物车成功!</div>
    <div class="btns">
      <a href="javascript:;" class="b-r" @click="toCart">进入购物车</a>
      <a href="javascript:;" @click="closeModal">继续购物</a>
    </div>
  </div>
</template>

子组件js部分:

methods: {
    toCart () {
      this.$router.push({
        path: ‘cart‘
      })
    },
    closeModal () {
      this.$emit(‘close‘)
    }
  }
this.$emit(‘close‘) 该方法向父组件传递了‘close‘事件

点‘继续购物’这个按钮时,需要关闭模态框。但是控制模态框显示的属性在父组件里。

父组件代码如下:

<transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut" :duration="200">
      <cart-modal v-show="cartModalShow" @close="closeCartModal"></cart-modal>
</transition>
v-show="cartModalShow" 控制着该模态框的显示和隐藏
@close="closeCartModal" 父组件使用close事件来触发closeCartModal方法关闭模态框

js代码:

methods: {  closeModal () {
      this.cartModalShow = false
  }}

这么写出来就发现其实用法也挺简单的,之前没有总结和整理,以为很难。

6.cubic-bezier是什么鬼?

参考文章:实用的 CSS — 贝塞尔曲线(cubic-bezier)

(1)animation-timing-function, transition-timing-function

(2)cubic-bezier 三次贝塞尔,为animation生成速度曲线的函数,cubic-bezier(<x1>, <y2>, <x2>, <y2>)

总结:2019年开始,每个工作日都会写一篇博客记录用到的或学到的技术,并没有那么难,写博客的目的纯粹是为自己做个记录,同时也是整理,当你需要把一件事情写出来时,你不得不十分清楚。以前也接触过不少的技术知识,基本上用过就丢一边了,下次再遇到时,又要重新找制作方法。

希望这是一个好的开始,坚持下去。我可能和某些人比差很远,但是每天都比自己更进步。

原文地址:https://www.cnblogs.com/basic0001/p/10245848.html

时间: 2024-08-11 03:21:59

每日技术总结:Toast组件,eslint,white-space,animate,$emit的相关文章

提示框的优化之自定义Toast组件之(二)Toast组件的业务逻辑实现

在java下org.socrates.mydiary.activity下LoginActivity下自定义一个方法showCustomerToast() ? 1 public class LoginActivity extends AppCompatActivity { 2 private void showCustomerToast(final int icon, final String message){ 3 LayoutInflater inflater=getLayoutInflate

Java文法(3)—— White Space

------------------------------------------------------------------------------- 说明: White space is defined as the ASCII space character, horizontal tab character, form feed character, and line terminator characters (§3.4). ---------------------------

微信小程序把玩(二十四)toast组件

原文:微信小程序把玩(二十四)toast组件 toast消息提示框,可用在提示一些信息,比如清楚缓存给用户一个友好的提示!或操作一些请求不想让用户有什么操作,toast也可以做到因为toast显示时其他操作是无效的 主要属性: wxml <!--点击button触发toast--> <button type="primary" bindtap="listenerButton">点击显示toast</button> <!--t

dom4j解析xml报错:Nested exception: org.xml.sax.SAXParseException: White space is required between the processing instruction target and data.

采用dom4j方式解析string类型的xml xml:        String string="<?xmlversion=\"1.0\" encoding=\"UTF-8\"?><ROOT><HEAD><INFO><BUSINESSNO>T065205072015000097</BUSINESSNO><BUSINESSTYPE>T</BUSINESSTYPE&g

Vant Weapp小程序蹲坑之使用toast组件

问题 使用Mpvue框架结合Vant Weapp组件库进行微信小程序开发中使用toast组件时,不小心又陷入"坑"中,当然主要还是路径问题. 注意点 使用toast组件时,与其它最普通的Vant Weapp组件相比,有几点需要注意.为了更方便理解,还是先上源码(index.vue),如下: <template> <div> <van-panel title="基础用法"> <van-picker :columns="

toast组件小结

简介:toast是"吐司"的意思,它属于android杂项组件,是一个简单的消息提示框,类似于javascript中的alert. 作用 显示文本 显示图片 显示图文 3.常用方法 show():显示消息提示框 makeText(Context context,Charsquence text,int duration):创建一个toast对象 setView(View view):该Toast显示的view组件 4.代码演示 MainActivity.class public cla

【Android应用开发技术:应用组件】Android事件处理机制

作者:郭孝星 微博:郭孝星的新浪微博 邮箱:[email protected] 博客:http://blog.csdn.net/allenwells Github:https://github.com/AllenWells 事件处理:不管是桌面应用还是手机应用都需要去响应用户的动作,这种为用户动作提供响应的机制就是事件处理. Android提供了两套事件处理机制,如下所示: 基于监听的事件处理 基于回调的事件处理 一般来说,基于回调的事件处理可用于处理一些通用性的事件,但对于某些特定的事件只能使

react---简易toast组件

组件核心代码: import React, { Component } from 'react' import PropTypes from 'prop-types'; // toast 弹框组件 class Toast extends Component { static defaultProps = { msg: '操作成功', // 默认提示语 time: 2000, // 默认弹框出现到消失的时间 } static propTypes = { msg: PropTypes.string,

【Android应用开发技术:应用组件】Fragment使用方法

作者:郭孝星 微博:郭孝星的新浪微博 邮箱:[email protected] 博客:http://blog.csdn.net/allenwells Github:https://github.com/AllenWells 一 Fragment管理与事务 Activity通过FragmentManager管理Fragment,FragmentManager可以完成以下功能: 调用findFragmentById()或findFragmentByTag()方法来获取指定的Fragment.在XML