首页 > 其他分享 >vue中经常要用到的代码

vue中经常要用到的代码

时间:2024-10-12 21:44:45浏览次数:1  
标签:vue String 用到 默认值 固定值 变量名 type 代码 defineProps

  • 属性使用动态值加固定值用
:a="`${变量名}` + '固定值'"

例如:

<svg :style="{width,height}">
    <!-- 内部需要用use结合使用 -->
    <use :xlink:href="`${prefix}` + 'mao'" :fill="color"></use>
    <!-- <use xlink:href="#icon-surf"></use> -->
</svg>
  •  给style标签设置动态值
:style="{属性名:变量名}"

例如:

<li :style="{color: item.done ? 'green' : 'red'}">
  • defineProps位变量名设置类型和默认值
defineProps({
   变量名:{
       type:变量类型,
       default:默认值  
    } 
})

例如:

defineProps({
    prefix: {
        type: String,
        default: "#icon-",
    },
    iconName:String,
    color:{
        type:String,
    },
});

 

标签:vue,String,用到,默认值,固定值,变量名,type,代码,defineProps
From: https://www.cnblogs.com/yansunda/p/18459393

相关文章