杂症记录
2025年4月9日...大约 2 分钟前端开发Issues
uni-app + vue进行小程序开发时的事件绑定问题
uni-app
基础组件规范,与小程序规范相近。如果了解小程序开发的话,uni-app的基础组件会感觉很熟悉。但需要注意组件上的事件绑定,需要以 vue 的事件绑定语法来绑定,如 bindchange="eventName" 事件,需要写成 @change="eventName"
<page-container
:show="showSuccessModal"
overlay-style="opacity: 0;"
@afterleave="handleCloseModal"
>
</page-container>
以上代码中的 afterleave
在微信官方文档中为 bind:afterleave
,如果在vue文件中按照微信小程序官方文档进行编写,会无法拿到 handleCloseModal
方法,因为vue的写法不同。
nvue文件中input设为disabled之后点击事件失效
失效点击事件代码:
<view class="input-style" @click>
<input
class="point-input"
v-model.trim="point"
:disabled="!isInputDisabled"
@blur="handleBlur()"
@focus="handleFocus()"
@input="handleInput($event)"/>
<text class="last">P</text>
</view>
网络上添加样式 pointer-events: none;
与将 disabled
改为 readonly
的方法均不可用, pointer-events: none;
可能只会在H5中有效,在APP中实测无效,而nvue的 input
甚至没有 readonly
这个属性,最后通过多种尝试,终于找到方法,APP中可将 @click
触发点击事件改为 @touchstart
,实测可行。
<view class="input-style" @touchstart="handleIsMax">
<input
class="point-input"
v-model.trim="point"
:disabled="!isInputDisabled"
@blur="handleBlur()"
@focus="handleFocus()"
@input="handleInput($event)"/>
<text class="last">P</text>
</view>
Safari浏览器中 window.open(url)
无法使用问题解决
查询原因为Safari浏览器因为安全限制,对异步函数中的 window.open(url)
不支持,但是我在非异步的函数中仍然无法正常使用 window.open(url)
,目前在多方实践后,实测可以为改用window.location.assign(url)
解决问题。