Element-ui之ElScrollBar組件滾動條的使用
文檔中并沒有關(guān)于這個 scrollbar組件的使用文檔,搜索一番得知這是一個隱藏組件,官方在 github 的 issues 中表示不會寫在文檔中,需要用的自己看源碼進(jìn)行調(diào)用。
scrollbar組件暴露了 native, wrapStyle, wrapClass, viewClass, viewStyle, noresize, tag 這7個 props屬性
props: {
native: Boolean, // 是否使用本地,設(shè)為true則不會啟用element-ui自定義的滾動條
wrapStyle: {}, // 包裹層自定義樣式
wrapClass: {}, // 包裹層自定義樣式類
viewClass: {}, // 可滾動部分自定義樣式類
viewStyle: {}, // 可滾動部分自定義樣式
noresize: Boolean, // 如果 container 尺寸不會發(fā)生變化,最好設(shè)置它可以優(yōu)化性能
tag: { // 生成的標(biāo)簽類型,默認(rèn)使用 `div`標(biāo)簽包裹
type: String,
default: 'div'
}
}
在頁面中使用 el-scrollbar組件
<template>
<div>
<el-scrollbar :native="false" wrapStyle="" wrapClass="" viewClass="" viewStyle="" noresize="false" tag="section">
<div>
<p v-for="(item, index) in 200" :key="index">{{index}} 這里是一些文本。</p>
</div>
</el-scrollbar>
</div>
</template>
vue.js 父組件如何觸發(fā)子組件中的方法
<template>
<div>
<button @click="clickParent">點擊</button>
<child ref="mychild"></child>
</div>
</template>
<script>
import Child from './child';
export default {
name: "parent",
components: {
child: Child
},
methods: {
clickParent() {
this.$refs.mychild.parentHandleclick("嘿嘿嘿");
}
}
}
</script>
解決el-input v-model.number 不能輸入小數(shù)點的問題,限制小數(shù)點后倆位
<el-input
v-model="formData[item.props]"
maxlength="11"
@input="(val) => {formData[item.props] = val.replace(/[^0-9.]/g, '').match(/^\d*(\.?\d{0,2})/g)[0] || null;}"
></el-input>
在在 Input 失去焦點時格式化為倆個小數(shù)點的格式,如 5 => 5.00
@blur="(e)=>{formData[item.props] = e.target.value ?parseFloat(e.target.value).toFixed(2) : ''}"
JavaScript將額外的參數(shù)傳遞給回調(diào)函數(shù)
如在一個vue組件中哄監(jiān)聽一個表單刪除的回調(diào)函數(shù),回調(diào)函數(shù)返回一個pid參數(shù);
<dataItem
:ref="item.val"
@deleteFormItem="deleteFormItem"
></dataItem>
//當(dāng)沒有增加額外的參數(shù)時
deleteFormItem(pid){
console.log(pid) // 正常輸出pid的值
}
加入要增加額外的參數(shù),使用ECMAScript 6箭頭功能:
<dataItem
:ref="item.val"
@deleteFormItem="(pid)=>deleteFormItem(pid,item)"
></dataItem>
//當(dāng)增加額外的參數(shù)時
deleteFormItem(pid,item){
console.log(pid,item) // 正常輸出pid,item的值
}