uni-app 安卓app端使用cover-image报错 无法使用

uni-app 安卓app端使用cover-image报错 无法使用

详细问题描述

uni-app(安卓app端)无法使用cover-image,编译报错。

[内容]

说明

普通vue文件,非nvue,编译模式自由组件模式。

编译错误

15:57:01.331 webviewScriptError
15:57:01.352 Cannot read property ‘indexOf’ of undefined;[Exparser] [Error] [Component] Lifetime Method Error @ wx-cover-image#attached
15:57:01.373 TypeError: Cannot read property ‘indexOf’ of undefined
15:57:01.394 at ne (uniapp://ready:1:2234)
15:57:01.415 at n.getRealRoute (uniapp://ready:182:277631)
15:57:01.435 at n._update (uniapp://ready:182:371243)
15:57:01.456 at n._attachedCb (uniapp://ready:182:290049)
15:57:01.477 at n.attached (uniapp://ready:182:288140)
15:57:01.498 at i.safeCallback (uniapp://ready:182:123029)
15:57:01.520 at i.call (uniapp://ready:182:122922)
15:57:01.545 at i (uniapp://ready:182:194190)
15:57:01.567 at i (uniapp://ready:182:194505)
15:57:01.588 at i (uniapp://ready:182:194505) at uniapp://ready:182
15:57:01.609 TypeError: Cannot read property ‘indexOf’ of undefined
15:57:01.630 at ne (uniapp://ready:1:2234)
15:57:01.651 at n.getRealRoute (uniapp://ready:182:277631)
15:57:01.672 at n._update (uniapp://ready:182:371243)
15:57:01.693 at n._attachedCb (uniapp://ready:182:290049)
15:57:01.714 at n.attached (uniapp://ready:182:288140)
15:57:01.735 at i.safeCallback (uniapp://ready:182:123029)
15:57:01.756 at i.call (uniapp://ready:182:122922)
15:57:01.777 at i (uniapp://ready:182:194190)
15:57:01.798 at i (uniapp://ready:182:194505)
15:57:01.818 at i (uniapp://ready:182:194505) at uniapp://ready:182

[源码]

<template>  
<cover-image src="/static/images/list.png"></cover-image>  
</template>

IDE运行环境说明

环境 版本号
HBuilderX 2.3.0.20190919

uni-app运行环境说明

环境 版本号
运行端 app
编译模式 自定义组件模式

App运行环境说明

环境 版本号
Android 8.1.0
手机型号 OPPO PACM00

更多关于uni-app 安卓app端使用cover-image报错 无法使用的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

app 平台 vue <cover-image> 只能放到原生组件上,例如 map、video,不支持嵌套其它组件 参考文档 https://uniapp.dcloud.io/component/cover-view?id=cover-image

更多关于uni-app 安卓app端使用cover-image报错 无法使用的实战教程也可以访问 https://www.itying.com/category-93-b0.html


我也是报错,怎么解决啊? 上面那人说的啥意思?

就是cover-image需要放在<map><cover-image></cover-image></map>组件里面,放在外面就报错。

这个错误是由于在普通vue文件中错误使用了cover-image组件导致的。cover-image是微信小程序原生组件,在uni-app的app端不能直接使用。

解决方案:

  1. 在app端应该使用uni-app的标准image组件替代:
<template>
  <image src="/static/images/list.png"></image>
</template>
  1. 如果确实需要覆盖原生组件(如地图上的标记),可以使用绝对定位的view+image组合实现类似效果:
<template>
  <view style="position:relative">
    <!-- 其他内容 -->
    <view style="position:absolute;z-index:999">
      <image src="/static/images/list.png"></image>
    </view>
  </view>
</template>
回到顶部