Skip to content

v-bind 在css中使用不生效 #3982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gyhyfj opened this issue Nov 9, 2022 · 3 comments
Open

v-bind 在css中使用不生效 #3982

gyhyfj opened this issue Nov 9, 2022 · 3 comments
Assignees

Comments

@gyhyfj
Copy link

gyhyfj commented Nov 9, 2022

release: v3.0.0-alpha-3060420220922001

编译成小程序,但确实看到编译成了css3变量

复现过程如下

// script 中
const picwidth = ref('100px')

// style 中
.pic{
  width: v-bind(picwidth)
}
@fastknifes
Copy link

是的不生效,复刻下面代码
vuejs/rfcs#231
在浏览器中有效,但微信小程序中无效

@deepthan
Copy link

贴个方法,找了好久没找到试出来了,希望可以帮助到你。
css 的 background: src(xxx) 使用变量,在 js 中拼接好 url

<script setup lang="ts">
const imgUrl = ref(
  'url(https://p3-passport.byteimg.com/img/mosaic-legacy/3795/3047680722~180x180.awebp)'
)
</script>

<style lang="less" scoped>
.compass {
  background: v-bind(imgUrl);
}
</style>

@GRCmade GRCmade self-assigned this May 23, 2025
@GRCmade
Copy link
Collaborator

GRCmade commented May 23, 2025

这个代码看起来在新版本可以正常运行了,可以更新一下看看

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants