gpt4 book ai didi

javascript - Vue.js 无法从方法添加样式

转载 作者:行者123 更新时间:2023-11-28 14:25:54 26 4
gpt4 key购买 nike

我想通过方法将一些样式添加到 html 元素中:

<div class="add-profile-img" v-bind:style="getBackgroundImg()">

方法是:

getBackgroundImg: function() {
return {
width: 180px;
height: 180px;
background-color: 'yellow';
background-image:url(this.BASE_URL +'/uploads/noimg.gif');
}
},

但是,我明白了

Syntax Error:   Identifier directly after number (79:13)

77 | getBackgroundImg: function() {
78 | return {
> 79 | width: 180px;
| ^

我该如何解决这个问题?

最佳答案

以像素为单位的尺寸需要采用字符串格式,以便函数返回有效的 JavaScript 对象:

return {   
width: '180px',
height: '180px',
'background-color': 'yellow',
'background-image': `url(${this.BASE_URL}/uploads/noimg.gif)`
}

关于javascript - Vue.js 无法从方法添加样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53287839/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com