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

2022-09-20 12:58:31 +08:00
 chunhai
		<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 这样写好像不对。

999 次点击
所在节点    Vue.js
5 条回复
sjhhjx0122
2022-09-20 17:01:42 +08:00
把 style 写成变量 直接:style="style" ? 好久没写小程序忘记语法了
yaphets666
2022-09-20 17:51:45 +08:00
:style="'background-image: url'+({{img_back.img}})+';height: 414upx;'"
yaphets666
2022-09-20 17:53:01 +08:00
上面多了两个大括号,:style="'background-image: url('+img_back.img+');height: 414upx;'"
Danswerme
2022-09-20 21:54:28 +08:00
:style="`background-image: url(${img_back.img});height: 414upx;`"
chunhai
2022-09-21 00:21:17 +08:00
@yaphets666 懂了懂了,感谢哈哈

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/881535

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX