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>

运行结果

运行结果

相关推荐
光影少年21 小时前
react和vue中的优点和缺点都有哪些
前端·vue.js·react.js
web_Hsir1 天前
uniapp + vue2 + pfdjs + web-view 实现安卓、iOS App PDF预览
android·前端·uni-app
EndingCoder1 天前
Node.js 与 TypeScript:服务器端开发
前端·javascript·typescript·node.js
打小就很皮...1 天前
基于 React 实现 Vditor 的可复用 Markdown 渲染组件
前端·react.js·markdown·vditor
EndingCoder1 天前
React 与 TypeScript:组件类型化
前端·javascript·react.js·typescript·前端框架
沛沛老爹1 天前
Web开发者实战:多模态Agent技能开发——语音交互与合成技能集成指南
java·开发语言·前端·人工智能·交互·skills
皮卡穆1 天前
Vue3 + Swiper.js 实现无缝轮播图组件
前端·javascript·vue
民乐团扒谱机1 天前
【数模美赛=美术大赛?】O奖论文图片复刻——高级绘图matlab代码集锦,让你摆脱画图“一眼MATLAB”的痛苦!
前端·人工智能·matlab
shehuiyuelaiyuehao1 天前
图书管理系统
java·服务器·前端
打小就很皮...1 天前
Vditor 实现混合模式评论,使用 Zustand 本地存储
前端·vditor·enablecomment