遇到了一个业务逻辑 就是在search页面 在自定义输入框中搜索商品,之后跳转到搜索出来的商品展示页面,但是商品搜索页面也有一个自定义输入框 需要我们把刚才搜索的值展示在输入框中,uni官方为我们提供了app的设置方法
// #ifdef APP-PLUS
var webView = this.$mp.page.$getAppWebview(); webView.setTitleNViewSearchInputText(e.keyWord)
// #endif
但是 没有写h5端的设置方法 我们可以用
// #ifdef H5
var searchInputDom = document.querySelector(".uni-input-input[type=search]");
var evt = new UIEvent('input', {
bubbles: false,
cancelable: false
});
searchInputDom.value = word;
searchInputDom.dispatchEvent(evt);
// #endif
来进行设置
完整代码
onLoad(e) {
this.keyWord = e.keyWord
let word = e.keyWord
// #ifdef APP-PLUS
var webView = this.$mp.page.$getAppWebview();
webView.setTitleNViewSearchInputText(e.keyWord)
// #endif
// #ifdef H5
var searchInputDom = document.querySelector(".uni-input-input[type=search]");
var evt = new UIEvent('input', {
bubbles: false,
cancelable: false
});
searchInputDom.value = word;
searchInputDom.dispatchEvent(evt);
// #endif
}