Vue的中的遇到的问题+笔记

news/2024/7/10 0:52:26 标签: vue, js

Vue笔记

vueVueuseinstallVueuseinstall_1">vue自定义组件(通过Vue.use()来使用)即install的使用,就是说Vue.use()产生的效果与install是一样的

export default {
  install(Vue) {     // 重点--->install
    Vue.prototype.$formatMoney = function(s, n) {
      n = n >= 0 && n <= 20 ? n : 2;
      s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + '';
      var l = s.split('.')[0].split('').reverse(); var r = s.split('.')[1];
      r = r == null ? '' : '.' + r;
      var t = '';
      //   console.log(l)
      if (l[l.length - 1] === '-') {
        // 负数不需要分隔号,

        for (var i = 0; i < l.length; i++) {
          if (l[i] === '-') {
            t += l[i] + ''
            continue
          }
          // 不是数组的倒数第二个元素才加"," ["0", "4", "5", "-"]
          t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length - 1 ? ',' : '')
          // i + 1 != l.length会变成-,540.00,因为在5时元素位置2+1为3非数组长度
          // t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? "," : "");
        }
      } else {
        for (var i = 0; i < l.length; i++) {
          t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '');
        }
      }
      return (
        t.split('').reverse().join('') + r
      )
    }
  }
}

http://www.niftyadmin.cn/n/565994.html

相关文章

预约时间列表

/*** 时间列表* $interval 间隔X分钟* */ function timeList($day7,$time108:00,$time222:00,$interval60){$date_list [];//日期列表$today_date strtotime(date(Y-m-d,time()));for($i0;$i<$day;$i){$date_title date(Y-m-d,$today_date($i*86400));$buff array();for…

Java 实现多个文件压缩成压缩包并下载至本地

1 Maven依赖 <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.6.2</version></dependency> 2 调试代码 /*** 多个文件压缩成压缩包** param response* throws IOException*/GetMapp…

css实现文字分散显示

css实现文字分散显示 为文字所在的容器添加如下属性即可 div {text-align-last:justify;text-align:justify;text-justify:distribute-all-lines; // 这行必加&#xff0c;兼容ie浏览器border: 1px solid red;width: 150px; }

Java 生成二维码(正常二维码和带Logo的二维码)

1 Maven依赖 <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.6.2</version></dependency><!--二维码--><dependency><groupId>com.google.zxing</groupId>…

Java Failed to parse multipart servlet request;the request was rejected because no multipart问题解决

问题描述&#xff1a; org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no …

原生的input实现没有边框,且点击时没有背景色和边框

input实现没有边框&#xff0c;且点击时只有光标&#xff0c;没有其他样式 为input添加如下属性&#xff0c;即可实现点击时只有光标&#xff0c;没有其他样式 input {outline:none;background:transparent;border:none;outline:medium;}*:focus {outline: none;background-c…

MyBatis Could not set property ‘xxx‘ of ‘class xxx‘ with value ‘xxx‘;argument type mismatch问题解决

问题描述&#xff1a; Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property userId of class UserDto with value 123 Cause: java.lang.IllegalArgumentException: argument type mismatch 问题分析&#xff1a; 1、Mapper文件中的userI…

iview中menu-item绑定事件失效

iview中menu-item绑定事件失效 主要是iview的menu-item的绑定点击事件要加native&#xff0c;才生效&#xff0c;如下所示。 <MenuItem:name"item.id"v-for"item in item.children":key"item.id":class"{ hide: isCollapsed }"cli…