Vue3 在SCSS中使用v-bind

template

先创建一个通用的页面结构

js 复制代码
<template>
  <div class="v-bubble-bg"></div>
</template>

js

在JS中先对需要用的数据进行定义:

可以是参数,也可以是data

js 复制代码
<script setup>
    const props = defineProps({
    bgColor: {
      type: String,
      default: '#000000'
    },
    bgWidth: {
      type: [Number, String],
      default: '100%'
    },
    bgHeight: {
      type: [Number, String],
      default: '100%'
    },
    color: {
      type: String,
      default: 'rgba(255,255,255,.6)'
    }
  })
  const pdata = reactive({
    size: '12px'
  })
</script>

css

js 复制代码
<style lang="scss" scoped>
 .v-bubble-bg {
    background-color: v-bind(bgColor);
    width: v-bind(bgWidth);
    height: v-bind(bgHeight);
    overflow: hidden;
    position: absolute;
    left: 0;
    top: 0;
    font-size:v-bind('pdata.size')
 }
</style>

运行结果

运行结果

相关推荐
光影少年9 分钟前
React Native第六章
javascript·react native·react.js
晓得迷路了12 分钟前
栗子前端技术周刊第 105 期 - npm 安全性加强、Storybook 10、htmx 4.0 Alpha 1...
前端·javascript·npm
七号练习生.c30 分钟前
CSS入门
前端·css·tensorflow
程序员爱钓鱼30 分钟前
Python编程实战——Python实用工具与库:Matplotlib数据可视化
前端·后端·python
程序员爱钓鱼34 分钟前
Python编程实战 - Python实用工具与库 - requests 与 BeautifulSoup
前端·后端·python
wyzqhhhh35 分钟前
前端跨页面通信
前端
G018_star sky♬40 分钟前
原生JavaScript实现输入验证的界面
javascript·css·css3
火龙谷44 分钟前
DrissionPage遇到iframe
开发语言·前端·javascript
千里马-horse1 小时前
搭建 React Native 库
javascript·react native·react.js·native library