vue加载更多+小点位数

改变小数位数

js普通版

//将传入数据转换为字符串,并清除字符串中非数字与.的字符  
     //按数字格式补全字符串  
     var getFloatStr = function(num){  
         num += '';  
         num = num.replace(/[^0-9|\.]/g, ''); //清除字符串中的非数字非.字符  
           
         if(/^0+/) //清除字符串开头的0  
             num = num.replace(/^0+/, '');  
         if(!/\./.test(num)) //为整数字符串在末尾添加.00  
             num += '.00';  
         if(/^\./.test(num)) //字符以.开头时,在开头添加0  
             num = '0' + num;  
         num += '00';        //在字符串末尾补零  
         num = num.match(/\d+\.\d{2}/)[0];  
     };   

js tofixed方法

 tofixed方法
    //方法可以把NUMBER四舍五入为指定小数位数的数字
     toFixed() 
     //语法
     //num是规定小数位数
     NumberObject.toFixed(num)   
     //具体用法
     var num=new Number(13.37)
     num=num.toFixed(1)

官方地址

http://www.w3school.com.cn/jsref/jsref_tofixed.asp

vue加载更多

<template>
    <div class="box">
    <div class="list">
        <ul>
            <li v-for="(item,index) in lists" :key="item.id">{{item.comment}}</li>
        </ul>
        <button @click="getlist()">加载更多</button>
    </div>
    </div>
</template>

<script>
    export default {
        name:"box",
        data(){
            return{
                lists:[],
                page:1,
                row:10
            }
        },
        methods:{
            getlist(){
            //page页数  rows条数
                this.$http.get("xxx?page="+this.page+"&rows=10").then((res)=>{
                   this.lists=this.lists.concat(res.data.data.list)
                })
            }
        },
        created(){
            this.getlist();
        }
        
    }
    
</script>

<style scoped>
    *{
        margin: 0;
        padding: 0;
    }
    li{
        list-style: none;
        margin-top: 10px;
    }
    .list{
        margin: 20px;
    }
    button{
        margin-top: 20px; 
        background: red; 
        border: none; 
        padding:5px 15px; 
        color: #fff;
    }
</style>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象。它将返回目标对象。 ...
    壹点微尘阅读 2,664评论 0 9
  • 审视一下你常用的工具/物品/人,想想为什么喜欢?喜欢的这些特质你可以用在哪里? 喜欢某些主播:传搭精致,不仅应用在...
    卞婧阅读 100评论 0 0
  • 【我觉得这是原耽】 【Summary:王先生和胡先生的错误恋爱方程式。】 【tips:大明星包养十八线。注意避雷。...
    阿静獍阅读 454评论 0 0
  • 孩子昨晚又磕到了,把前晚让狗吓得磕的腿又加重了,青的更厉害了,说是自己没注意有块石头,光和侯见宇说话了,我说娃啊?...
    栩宝妈妈阅读 232评论 0 0
  • 近来,我开始练习写作,按照“微习惯”的原理,每天写上一段话,有时进入心流,也能写出些自认为不错的文章,然后忍...
    探索未知阅读 201评论 0 0