从后台接口动态获取样式字段渲染html

动态渲染样式

在后台管理项目中可以设置前台首页banner上的按钮的位置字体颜色等等样式,虽然知道用style动态绑定样式,但是很多写法都是错误的,弄了许久才弄好,现在把代码贴出来记录一下

  1. 后台接口返回的数据中样式都写道一个字段里了先转换一下:

    scope.extend=JSON.parse(scope.extend)
    
    temporary.language=scope.language
    
    temporary.title=scope.title
    
    temporary.imageUrl=scope.url
    
    temporary.bottom=scope.extend.bottom
    
    temporary.right=scope.extend.right
    
    temporary.buttonStyle=scope.extend.buttonStyle
    
    temporary.fontSize=scope.extend.fontSize
    
    temporary.color1=scope.extend.backgroundColor
    
    temporary.color2=scope.extend.borderColor
    
    temporary.color=scope.extend.color
    
    temporary.content=scope.extend.content
    
    temporary.website=scope.link_url
    
  2. 绑定到元素上

    <div class="wrap" :style="{backgroundImage:'url('+priviewData.imageUrl+')'}" v-if="priviewDialog">
      <div class="NuxtTo" :style="{bottom:`${priviewData.bottom}`,right:`${priviewData.right}`,borderRadius:`${priviewData.buttonStyle}`,fontSize:`${priviewData.fontSize}`,background:`${priviewData.color1}`,borderColor:`${priviewData.color2}`,color:`${priviewData.color}`,}" @click="goto" v-if="priviewData.is_show">
      {{priviewData.content}}
    	</div>
    </div>
    
  3. 这样就可以在页面上动态的显示出来样式了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值