美丽时光 發表於 2020-6-1 18:13:00

uni-app之uni.showToast()image路径问题

<p><strong>uni-app的API中,showToast的icon值只有success,loading,none三种显示,失败没有图标。如果失败时需要显示图标,就要用到自定义图标<span style="color: rgba(255, 102, 0, 1)">&nbsp;<code>image</code>&nbsp;</span>了。</strong></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> <span style="color: rgba(0, 0, 0, 1)">    uni.showToast({
</span><span style="color: rgba(0, 128, 128, 1)">2</span>         title: '扫码失败'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">3</span>         image:'/static/lost.png',   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">要写根路径,不要写相对路径</span>
<span style="color: rgba(0, 128, 128, 1)">4</span>         duration: 3000<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">5</span>   })</pre>
</div>
<p><strong>结果如下:<img src="https://common.cnblogs.com/images/loading.gif"></strong></p>
<p>&nbsp;<img src="https://img2020.cnblogs.com/blog/1893240/202006/1893240-20200601181123551-1780069326.png"></p>
<p>&nbsp;</p>
<p><span style="color: rgba(255, 0, 0, 1)"><strong>特别<strong>注</strong>意:</strong></span><br><strong>在components下的组件,图片路径用&nbsp;<code>/static/lost.png</code>&nbsp;这样的根路径形式,不要用…/static 或者 …/…/static 的形式。</strong><br><strong>在有些平台不报错也不显示,有些找不到路径。</strong></p><br><br>
来源:https://www.cnblogs.com/w1111/p/13026597.html
頁: [1]
查看完整版本: uni-app之uni.showToast()image路径问题