uniapp 开发中的的小技能收藏

1.点击事件冒泡穿透问题

@click.stop与@click.prevent

@click.stop 阻止事件冒泡

@click.prevent 阻止事件的默认行为,

<a href="http://www.baidu.com" @click.prevent="test4">百度一下</a>   //阻止a标签跳转,仅执行函数test4

<form  action="/xxx"   @submit.prevent="test5">   //阻止表单提交,仅执行函数test5

         <input type="submit" value="注册">
</form>

2.uniapp在页面跳转时,若URL太长的字符串会导致数据传递失败

url有长度限制,太长的字符串会传递失败,可使用窗体通信全局变量,或encodeURIComponent等多种方式解决,如下为encodeURIComponent示例的解决方法。

<navigator :url="'/pages/test/test?item='+ encodeURIComponent(JSON.stringify(item))"></navigator>
// 在下一个.vue页面接受参数
onLoad: function (option) {
    let item = JSON.parse(decodeURIComponent(option.item));
}

3.子父组件传递参数:https://www.cnblogs.com/Alex-Song/p/12156989.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章