初始化Data中定义的属性
Object. assign ( this . $data. formData, this . $options. data ( ) . formData) ;
UI框架props供用到二次封装组件(知识点:
p
r
o
p
s
,
props,
p ro p s , listeners)
< template>
< Table v- bind= "$props" v- on= "$listeners" stripe>
< template v- for = "(i, name) in $scopedSlots" : slot= "name" slot- scope= "{ row, column,index }" >
< slot : name= "name" v- bind= "{ row, column , index }" / >
< / template>
< / Table>
< / template>
< script>
import { Table } from "view-design" ;
export default {
props : {
... Table. props,
num : {
type : Boolean
} ,
} ,
data ( ) {
return { } ;
} ,
mounted ( ) {
console. log ( "$props" , this . $props) ;
console. log ( "$slots" , this . $slots) ;
console. log ( "$scopedSlots" , this . $scopedSlots) ;
} ,
} ;
< / script>
常用处理函数
金额处理
unit ( val ) {
val = Number ( val) ;
if ( val > 9999 && val < 100000000 ) {
val = ( val / 10000 ) . toFixed ( 2 ) + "万" ;
} else if ( val > 99999999 ) {
val = ( val / 100000000 ) . toFixed ( 2 ) + "亿" ;
} else if ( val < 9999 ) {
val = val. toFixed ( 2 ) + '元'
}
return val;
} ,
百分比处理
unitBaif ( val ) {
val = Number ( val) ;
return ( val * 100 ) . toFixed ( 2 ) + "%" ;
} ,
模拟链接跳转
newPageSkit ( url, type ) {
var a = document. createElement ( "a" ) ;
let appDom = document. getElementById ( type) ;
a. setAttribute ( "href" , url) ;
a. setAttribute ( "target" , "_blank" ) ;
a. setAttribute ( "id" , "js_a" ) ;
if ( document. getElementById ( "js_a" ) ) {
appDom. removeChild ( document. getElementById ( "js_a" ) ) ;
}
appDom. appendChild ( a) ;
a. click ( ) ;
}
img错误处理函数
< div class = "item-logo" >
< img v- if = "checkImg(item.pictureUrlPc)" : src= "item.pictureUrlPc" alt= "图片加载失败" class = "item-strip" >
< p v- else class = "item-logo-text" > { { item[ config. logoNmae] . slice ( 0 , 4 ) } } < / p>
< / div>
methods : {
checkImg ( imgSrc ) {
console. log ( "图片加载失败" ) ;
new Promise ( ( resolve, reject ) => {
var ImgObj = new Image ( ) ;
ImgObj. src = imgSrc;
ImgObj. onload = function ( res ) {
resolve ( res) ;
} ;
ImgObj. onerror = function ( err ) {
reject ( err) ;
} ;
} )
. then ( ( ) => {
return false ;
} )
. catch ( ( ) => {
return true ;
} ) ;
} ,
} ,