最近遇到一个需求,在一个<text>文本中的前后添加空格占位符,总所周知,我并不会前端,于是我查察了原生微信小程序以及uniapp官方文档,得到了以下答案:
- 原生微信小程序官方文档

- uniapp官方文档

从文档可以知道我们可以用 , , 等等作为占位符实现空格结果,然而我试了很多次都没有到达结果,以下是错误树模:
- 错误树模一:错误缘故起因:decode默认是false,也就是说默认是不会解码的,必要手动设置为true
- 错误树模二:
- <text decode> 爱吃炸排骨</text>
复制代码 错误缘故起因:&ensp必要用{{}}括起来,于是!!!
- 准确树模:
- <text decode>{{myText}}</text>
复制代码 在.js文件(原生微信小程序)或 <script>(uniapp)中写内容- myText: ' 爱吃炸排骨 '
复制代码 然后大功告成!!!其实我还试过很多多少错误的但是这里就不一 一演示了
下面是完整文件(同样也分为了uniapp和原生):
uniapp:(为了演示的显着一点我加了很多多少个占位符)
- <template> <view> <text decode>{{myText}}</text>
- </view></template><script> export default { data() { return { myText: ' 爱吃炸排骨 ' } }, methods: { } }</script><style></style>
复制代码 原生微信小程序:
- <text decode>{{myText}}</text>
复制代码
- Page({
- data:{
- myText: '    爱吃炸排骨 '
- },
- onLoad: function() {
- }
- })
复制代码 |