我试图在某些情况下禁用提交按钮,但它不起作用。当我在浏览器中检查元素时,无论条件返回 true 还是 false,都会呈现这个元素。
在浏览器中呈现的元素
<button type="submit" disabled="" class="bg-yellow-500 text-white mt-4 disabled:bg-yellow-300 px-3 py-2 rounded-md">Submit</button>
Run Code Online (Sandbox Code Playgroud)
代码
state = {
formIsVaild: false
}
render() {
<button type="submit" disabled={!this.state.formIsVaild} className="bg-yellow-500 text-white mt-4 disabled:bg-yellow-300 px-3 py-2 rounded-md">Open Discussion</button>
}
Run Code Online (Sandbox Code Playgroud)
我什至删除了条件并尝试了这个......
state = {
formIsVaild: false
}
render() {
<button type="submit" disabled className="bg-yellow-500 text-white mt-4 disabled:bg-yellow-300 px-3 py-2 rounded-md">Open Discussion</button>
}
Run Code Online (Sandbox Code Playgroud)
无论我传递给 disable 属性的值是什么,disabled=""get 都会在 HTML 中呈现。我什至尝试使用类型为 submit 的输入而不是按钮,我得到了相同的结果。我不确定这里发生了什么......有什么帮助吗?
最小的例子
import React, { Component } from 'react';
class FormData extends Component { …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取单个帖子的详细信息,但我不断收到此错误;错误类型错误:无法读取 Object.eval [as updateRenderer] 中未定义的属性“title”。虽然数据在 console.log 中被正确获取,但它没有显示在页面本身上。当我执行 {{post?.title}} 时,错误消失了,但结果仍然没有出现在页面上,但在 console.log 中正确显示
离子框架:v4 操作系统平台:Windows 10
售后服务
getAllPosts(): Observable<any> {
return this.http.get(`${this.url}`).pipe(
map(results => {
console.log('Raw: ', results);
return results['posts'];
})
);
}
getPost(postId: string) {
return this.http.get(`${this.url}/${postId}`);
}
Run Code Online (Sandbox Code Playgroud)
post.page.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { PostService } from '../post.service';
@Component({
selector: 'app-post',
templateUrl: './post.page.html',
styleUrls: ['./post.page.scss'],
})
export class PostPage implements OnInit {
loadedPost: any;
constructor(private activatedRoute: ActivatedRoute, private postService: PostService) { …Run Code Online (Sandbox Code Playgroud)