chunhai
V2EX  ›  Vue.js

vue 数据绑定和小程序的问题

By chunhai at 2022 年 9 月 20 日 · 2278 次点击
		<view class="bg-img bg-mask flex align-center"
			style="background-image: url('{{img_back.img}}');height: 414upx;">
			<view class="padding-xl text-white">
				<view class="padding-xs text-xxl text-bold">
					{{img_back.title}}
				</view>
				<view class="padding-xs text-lg">
					{{img_back.desc}}
				</view>
			</view>
		</view>

这个 style 俩边的图片链接该怎么写啊?我按照小程序模板语法可以这么写,vue 这样写好像不对。

5 条回复
linkopeneyes
   1
linkopeneyes  
   2022 年 9 月 20 日
把 style 写成变量 直接:style="style" ? 好久没写小程序忘记语法了
yaphets666
   2
yaphets666  
   2022 年 9 月 20 日
:style="'background-image: url'+({{img_back.img}})+';height: 414upx;'"
yaphets666
   3
yaphets666  
   2022 年 9 月 20 日
上面多了两个大括号,:style="'background-image: url('+img_back.img+');height: 414upx;'"
Danswerme
   4
Danswerme  
   2022 年 9 月 20 日
:style="`background-image: url(${img_back.img});height: 414upx;`"
chunhai
   5
chunhai  
OP
   2022 年 9 月 21 日
@yaphets666 懂了懂了,感谢哈哈
© 2026 V2EX · 28ms · 3.9.8.5