onLoad: function (options) { if(options.index != undefined){ this.setData({ tabIndex:options.index }) } this.getDetail() }, 用uniapp改写
时间: 2024-02-24 10:55:30 浏览: 32
在uni-app中,页面的生命周期函数名字与小程序有些不同,onLoad对应的是onLoad生命周期函数。在该函数中,也可以通过options参数获取页面跳转时传递的参数。需要注意的是,在uni-app中,setData方法需要通过this.$set来调用。因此,可以将原来的代码改写为:
```
onLoad: function (options) {
if(options.index != undefined){
this.$set(this.data, 'tabIndex', options.index);
}
this.getDetail();
},
```
这段代码与原来的代码功能相同,如果传递的参数options中包含index属性,则将该属性的值作为当前页面的tabIndex,并将该值设置到页面的data中。通过this.$set更新data中的数据,从而触发页面的重新渲染。最后,调用getDetail函数,用于获取页面详情数据。
相关问题
查找错误点<script> var mcText = document.querySelector(`.mcText`) var accountedText = document.querySelector('.accountedText') var passwordText = document.querySelector('.passwordText') var registerDiv = document.querySelector('.registerDiv') var isAgree = false; //注册按钮的点击事件 registerDiv.onclick = function () { if(isAgree == true){ // history.back() var ajax = new XMLHttpRequest() var string = "mc="+mcText.value+"username="+accoundedText.value+'&password='+passwordText.value; ajax.open('get','http://localhost:8080/registUser?'+string) ajax.send() } else { alert("请输入名称账号密码") } } ajax.onload = function (){ console.log(ajax.responseText); } //监听这三个输入框失去焦点 mcText.onblur = function (){ isAgree = isAgreeLogin(); } accountedText.onblur = function (){ isAgree = isAgreeLogin(); } passwordText.onblur = function (){ isAgree = isAgreeLogin(); } //在失去焦点的时候,判断三个输入框是否都有值了,如果有则高亮显示,如果无则不亮 function isAgreeLogin() { if(mcText.value !='' && accountedText.value != ''&& passwordText.value != ''){ registerDiv.style.backgroundColor = "#648ceb" registerDiv.style.boxShadow = "2px 2px 2px #9eb8f6" return true } else { return false } } </script>
您的代码中应该把 `var ajax = new XMLHttpRequest()` 放到 `registerDiv.onclick` 的函数体内部,否则会造成 ajax 未定义的错误。
正确的代码应该是这样的:
```
var mcText = document.querySelector(`.mcText`);
var accountedText = document.querySelector('.accountedText');
var passwordText = document.querySelector('.passwordText');
var registerDiv = document.querySelector('.registerDiv');
var isAgree = false;
registerDiv.onclick = function () {
if (isAgree == true) {
var ajax = new XMLHttpRequest(); // 将此行代码放到函数体内部
var string = "mc=" + mcText.value + "username=" + accountedText.value + '&password=' + passwordText.value;
ajax.open('get', 'http://localhost:8080/registUser?' + string);
ajax.send();
} else {
alert("请输入名称账号密码");
}
}
ajax.onload = function () {
console.log(ajax.responseText);
}
mcText.onblur = function () {
isAgree = isAgreeLogin();
}
accountedText.onblur = function () {
isAgree = isAgreeLogin();
}
passwordText.onblur = function () {
isAgree = isAgreeLogin();
}
function isAgreeLogin() {
if (mcText.value != '' && accountedText.value != '' && passwordText.value != '') {
registerDiv.style.backgroundColor = "#648ceb";
registerDiv.style.boxShadow = "2px 2px 2px #9eb8f6";
return true;
} else {
return false;
}
}
```
请注意,这只是一种可能的解决方案。如果问题仍然存在,请提供更多上下文信息和完整的代码,以便我更好地帮助您。
onLoad: function (options) { console.log("获取到:"+options.id); this.setData({ id:options.id, buid:options.buid, }); },
这段代码是小程序中页面的生命周期函数之一,即页面加载时执行的函数。在传递参数时,可以通过 options 参数来获取传递的参数。在这段代码中,通过 console.log 输出获取到的参数 id,然后将其赋值给该页面的 data 中的 id,同时将 buid 也赋值给该页面的 data 中的 buid。这样就可以在该页面中使用这些参数进行相应的操作了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)