如何通过QT C basd代码将文件上传到OpenAI Assistant API
OpenAI Assistant API 允许客户端在文件中上传额外的“知识”,以便 Assistant 与 ChatGPT 配合提供更多定制/私人 AI 响应。 我的客户是C b...
首页 &... <div class="menu-bar"> <ul> <li><a href="/Home/index.html"> <i class="fa fa-house"></i>Home</a> </i></li> < ul > </div> <style> .menu-bar ul li a:hover { color: black; transition: all 0.2s; border-inline-end: 2px solid; border-block-end: 2px solid; </style> 我想从 fa fa-house 的 cdn 图标中删除 :hover 效果。 <div class="menu-bar"> <ul> <li> <i class="fa fa-home"></i> <a href="/Home/index.html"> Home </a> </li> </ul> </div> <style> .menu-bar ul li a:hover { color: black; transition: all 0.2s; border-inline-end: 2px solid; border-block-end: 2px solid; } .menu-bar ul li i{ pointer-events: none; } </style> <div class="menu-bar"> <ul> <li><i class="fa fa-house"></i><a href="/Home/index.html"> Home</a> </i></li> <ul > 只需从 <i> 标签中取出 <a> 元素(图标)即可。 你可以试试这个:- <div class="menu-bar"> <ul> <li><i class="fa fa-house"><a href="/Home/index.html"> </i>Home</a> </i></li> </ul> </div> <style> .menu-bar ul li a:hover { color: black; transition: all 0.2s; border-inline-end: 2px solid; border-block-end: 2px solid; } </style>
有没有一种方法可以在React中单击时嵌入链接来重定向组件?
我有一个导航栏,其路线设置如下: 导入'../styles/Nav.css' 从 'react-router-dom' 导入 { BrowserRouter as Router, Routes, Route, Link} 从 '../components/Home' 导入 { Home }
使用 -u 1000:1000 选项进行 docker run 时,Jenkins docker sudo 错误
我有一个 docker 映像,可以在使用以下 DockerFile 创建的 Jenkins 管道中使用: # 根据 来自 ros:noetic # 用户 工作目录/home/用户 运行 useradd --create-home --shell /bin/bash 用户 \ &a...
LibClamAV 错误:cli_loaddbdir():在 /var/lib/clamav 中找不到受支持的数据库文件
当我尝试扫描 /home 目录时,出现此错误。 [root@ip-172-31-34-67 ~]# clamscan /home LibClamAV 错误:cli_loaddbdir():在 /var/lib/clamav 中找不到受支持的数据库文件 错误:不能
React中react-router-dom最新版本如何实现延迟加载
我想使用Typescript在React中实现延迟加载。我收到打字稿错误。 常量应用程序 = () => { 返回 ( 我想使用 Typescript 在 React 中实现延迟加载。我收到打字稿错误。 const App = () => { return ( <RouterProvider router={createBrowserRouter( createRoutesFromElements( <Route> <Route path="/" element={<Outlet/>}> <Route index element={<Home />} /> <Route path="contact" element={<Contact />} /> <Route path="about" element={<About />} /> <Route path="*" element={<Navigate to="/" replace />} /> </Route> </Route> ) )} /> ) }; export default App; 下面的代码不起作用 <Route> <Route path="/" element={<Outlet/>}> <Route index lazy={() => import("./Home")} /> <Route path="contact" lazy={() => import("./Contact")} /> <Route path="about" lazy={() => import("./About")} /> <Route path="*" element={<Navigate to="/" replace />} /> </Route> </Route> const Home= lazy(() => import("./screens/home")); const About= lazy(() => import("./screens/about")); <Route> <Route path="/" element={<Outlet/>}> <Route index element={<Suspense fallback={<div>Loading...</div>}> <Home/> </Suspense> /> } /> <Route path="about" element={<Suspense fallback={<div>Loading...</div>}> <About/> </Suspense> /> } /> <Route path="*" element={<Navigate to="/" replace />} /> </Route> </Route>
每当用户打开“localhost:3000”时,我必须将用户重定向到“localhost:3000/home/dashboard”
每当用户打开 localhost:3000 时,我都必须将用户重定向到 localhost:3000/home/dashboard。如何让路由器在 React 应用程序中执行此操作? 我尝试过,但没有得到结果
部分代码 area_file = open('/home/gkrish19/SIAM_Integration/Final_Results/area_chiplet.csv', 'a') area_file.write('NoP 驱动程序总面积为' + ' ' + str(Nop_area) + ' ' + 'um^2') 区域文件.c...
我正在尝试在pycharm上运行manage.py runserver并返回属性错误 文件“C:\Users\user\PycharmProjects\Diabetes Prediction\Diabetes_prediction\Diabetes_Prediction\urls.py&qu...
我遵循了本教程。 https://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html 但不幸的是,它似乎不起作用。 (payo-py3.10) PS C:\Users\ser> 设置 MY_VAR=a...
我有一个像这样的 docker-compose.yml : 版本:'2' 服务: 后端: 建造: 语境: 。 卷: - .:/home/ll/东西 端口: - '8000:80' 这总是增加音量...
在 ./progress 中下载完文件后,如何从完成的文件夹中种子到 transmiion-daemon?
我修改了settings.config,添加了以下两个属性: “script-torrent-done-enabled”:true, "script-torrent-done-filename": "/home/ubuntu/dottemplates/
我正在构建 ASP.NET 8 Web API。 第一次运行Postman时,出现以下错误: 获取 https://localhost:5001/home 错误:连接ECONNREFUSED 127.0.0.1:5001 请求标头 用户-
Flutter - 错误:JAVA_HOME 在 macos 中设置为无效目录
我正在使用 android studio 开发 android 原生和 flutter 项目。我的android本机项目jdk设置为/Applications/AndroidStudio.app/Contents/jbr/Contents/Home并且我已经下载了...
}> } /> <SideBar /> <Routes> <Route path='/' element={<Body />}> <Route path='/' element={<Home />} /> <Route path='setting' element={<Setting />} /> </Route> <Route path='/service' element={<ServiceLayout />}> <Route path='/service' element={<Service />} /> </Route> </Routes> <Article /> </div> 我不想在服务组件中渲染文章组件。我怎么做?请帮助我。 Article组件无条件在路由内容下渲染。 <div className='App'> <SideBar /> <Routes> <Route element={<Body />}> <Route path='/' element={<Home />} /> <Route path='setting' element={<Setting />} /> </Route> <Route path='/service' element={<ServiceLayout />}> <Route index element={<Service />} /> </Route> </Routes> <Article /> // <-- always rendered! </div> 简单的解决方案就是从 JSX 中删除 Article: <div className='App'> <SideBar /> <Routes> <Route element={<Body />}> <Route path='/' element={<Home />} /> <Route path='setting' element={<Setting />} /> </Route> <Route path='/service' element={<ServiceLayout />}> <Route index element={<Service />} /> </Route> </Routes> {/* <Article /> removed */} </div> 但这可能不是您真正想要的。另一种选择是有条件地在路线上渲染它。 示例: <div className='App'> <SideBar /> <Routes> <Route element={<Body />}> <Route path='/' element={<Home />} /> <Route path='setting' element={<Setting />} /> </Route> <Route path='service' element={<ServiceLayout />}> <Route index element={<Service />} /> </Route> </Routes> <Route path='article' element={<Article /> } /> // <-- only on "/article" path </div>
Ubuntu 无法将 tar.bz2 解压到 /usr/local
我想在我的 Ubuntu(10.0+ 版本)中安装 boost_1_54_0。我将包下载到/home/Downloas 然后我尝试按照boost官方网站给出的步骤进行操作。 http://www.boost.org/doc/libs/
InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor:生命周期事件ApplicationXXXX是一个noop
我在做什么? 使用codedeploy在ec2中部署应用程序。 操作系统:Linux 文件: - 来源: / 目的地:/home/ec2-user/xxx-api file_exists_behavior:覆盖 权限: - 对象:/...
我正在尝试使用 sshfs 在我的虚拟 Linux 机器上安装亚马逊 Web 服务器的 ec2 实例的驱动器。 我使用的命令如下: Sameeksha@technician:~$ sudo sshfs -i $HOME/Downloads/ama...
使用 Clang-CL 跨 Windows 构建 ICU(来自 Conan)
我在使用 Clang-CL 构建 Conan 的 ICU 配方时遇到了一些麻烦。 我使用以下主机配置文件在 Linux 上编译此项目: {% set msvc_install_root = os.getenv("HOME&quo...
在 cygwin 中构建 binutils 时出现“make”命令错误
我使用 cygwin 为我的平台构建 binutils。我遵循 GCC 交叉编译器文章并堆栈了“make”命令。我使用的命令: 导出 PREFIX="$HOME/opt/cross" ../比努...
Openpyxl - 如何在 Python 中仅读取 Excel 文件中的一列?
我只想从电子表格中提取 A 列。我有下面的代码,但它从所有列中提取。 从 openpyxl 导入工作簿,load_workbook wb=load_workbook("/home/ilissa/文档/
我有一个要求,即在 Unix 路径上接收 XML 文件。我想将此 xml 文件的内容复制到 Postgres 表的一列中。 收到的示例文件:/home/bojack/test.xml ...
Laravel:ERR_TOO_MANY_REDIRECTS
我正在尝试在 Laravel 中编写基本身份验证系统,这导致了重定向循环。 首先,我只访问“localhost”域,然后当我什至没有经过身份验证时,它会将我发送到 /home ...
如何下载使用 StreamWriter 编写的 xml 文件作为 xml 文件
我有一个使用 StreamWriter 用 C# 编写的 XML 文件,代码如下: 字符串文件名 = Session.SessionID + ".xml"; 字符串文件路径 = "h:\root\home\mchinni-001\www\site1\OUTFolde...
为什么我的图像(Yocto)无法在rcar_canfd.c中应用更改?
我是 Yocto 的新手,我对 rcar_canfd.c 有问题: 在我的项目中,我在以下位置找到 rcar_canfd.c: ./home/u/hungphung/S4_APD/build-spider-gateway/tmp/work/aarch64-poky-linux/linux-libc-headers/5.10-...
我使用 Home-brew 在 macOS Monterey 上安装了 OpenCV 4.8.1_5。 它似乎没有安装包含图像的示例文件夹。 所以下面的行失败了: std::string image_path = 样本::
usercustomize.py 自动运行但不存储变量和函数
我已按照本主题中的说明进行操作: 有没有办法让python启动时始终执行脚本? (类似 R 中的 site.profile) python3 -m site 的部分输出: USER_SITE:'/home/<
您能帮我弄清楚为什么我的 Adguard Home 实例在初始设置期间通过端口 3000 工作,但完成设置后我无法访问端口 80(Azure We 也不能...
问候。 我从两年前就有了一个不和谐的音乐机器人,当时它工作得很好。但现在当我尝试播放某些东西时,我收到以下错误: 文件“/home/runner/Goorbebot...
我尝试在cmd中执行Java程序,但使用“java”运行程序时出现错误
我可以在VS code中成功运行程序: 在 VS Code 中运行 命令: /usr/bin/env /usr/lib/jvm/java-17-openjdk-amd64/bin/java -XX:+ShowCodeDetailsInExceptionMessages -cp /home/bignosecss/.vscode-...
filesystem::copy 返回无效参数,但参数是现有的 fs::path 变量
我正在使用 std::filesystem (fs) 库处理项目中的文件。我存储为 fs::path 变量的所有路径。我的代码是: int main(){ std::filesystem::path root_dir = "/home/xyz/study/
如何通过 GHCup+cabal 管理 XMonad(以及 xmobar 和其他相关内容)?
事实证明执行起来就足够了 cabal install --package-env=$HOME/.config/xmonad --lib 基础 xmonad xmonad-contrib 但我不明白的是: 为什么这有效? 为什么要更新...
突然 docker run 找不到 libz.so.1 [已关闭]
我使用 docker build 和 docker run 已经好几个星期了。我想放入容器中的可执行文件也运行良好。 突然我得到了这个我不明白的错误: root@DESKTOP-EVLULFV:/home/sim...
将证书上传到AAD应用程序的powershell命令是什么?
在Azure门户中,我可以在AAD下创建一个应用程序,导航到“Home (myTenant) -> 应用程序注册 -> (myApp) -> 设置 -> 密钥”,上传作为应用程序证书的公钥...
我们可以将 s3 位置传递到 Dag 文件夹到 Ec2 实例 Apache Airflow 吗
如何将 S3 位置传递到文件airflow.cfg 中的 dag 文件夹中。 目前我的airflow.cfg 看起来像:- dags_folder = /home/airflow/airflow/dags 我想使用 s3 位置的 dags。我该怎么办...
API 不工作/http 错误 SocketException:在发布版本中查找主机失败(在调试模式下工作)对于 Flutter
获取有关 path_provider-1.5.1 和 API 不工作的一些注释,我通过 http/dio 在 Release Build(在调试模式下工作)中集成了 Flutter。 笔记: /home/webelightpc/文档/
我正在将 React 与 Next.js 结合使用。 我想在我的主页上创建一个带有粒子的网站,它对应于名为“Home”的组件。颗粒应该在组件上消失...
在我的 Home.js 中我有以下代码 从“反应”导入反应; 导入'./Home.css'; 常量文本变体 = {...} 常量主页 = () => { 返回 ( ... 在我的 Home.js 中,我有以下代码 import React from 'react'; import './Home.css'; const textVariants = {...} const Home = () => { return ( <div id='home' className='page'> <motion.div className='text-wrapper' variants={textVariants} initial='initial' animate='animate'> <motion.div className='text-container' variants={textVariants}> <motion.h1 variants={textVariants}>NAME</motion.h1> <motion.h2 variants={textVariants}>An enthusiatic university student</motion.h2> </motion.div> </div> ); }; export default Home; 在 Home.css 中, .text-wrapper { max-width: 1366px; height: 100%; } .text-container { height: 100%; width: 50%; padding-left: 10%; h1 { letter-spacing: 10px; font-size: 50px; margin-bottom: -5%; } h2 { font-size: 80px; } } 我有 About.js 和 About.css 以及以下内容, import './About.css'; const About = () => { return ( <div id='about' className='page'> <div className='text-container'> <h1>About Me</h1> </div> </div> ); }; 但是 About.js 应用了 Home.css 中的内容,即 .text-container。我该如何避免这种情况?我不知道为什么 Home.css 被应用到 About.js 即使我没有导入它。 在React js中,任何根组件中导入的css文件适用于整个项目。 css 类可以在项目层次结构中的任何位置访问。 我们无法避免这种情况,因为文件被应用于根目录。您必须为不同的组件使用特定的类名称。 专业提示:创建可重用的组件,以便您可以将相同的类应用于每个相同的组件..
这是代码 从“反应”导入反应; 从“react-dom/client”导入ReactDOM; const 标头 = () => { 返回 ( <... 这是代码 import React from "react"; import ReactDOM from "react-dom/client"; const Header = () => { return ( <div className="header"> <div className="logo-container"> <img className="logo" src="/assets/logo.jpg" /> </div> <div className="nav-items"> <ul> <li>Home</li> <li>About us</li> <li>Contact us</li> <li>Cart</li> </ul> </div> </div> ); }; const AppLayout = () => { return ( <div className="App"> <Header /> </div> ); }; const root = ReactDOM.createRoot(document.getElementById("root")); root.render(<AppLayout />); 请帮助我,因为我是新反应。 我期待在服务器上显示图像 如果仍然不起作用,请尝试在上面的代码中添加 alt 标签 试试这个: 从“react”导入React; 从“react-dom/client”导入 ReactDOM; const Header = () => { return ( <div className="header"> <div className="logo-container"> <img className="logo" src={process.env.PUBLIC_URL + "/assets/logo.jpg"} alt="Logo" /> </div> <div className="nav-items"> <ul> <li>Home</li> <li>About us</li> <li>Contact us</li> <li>Cart</li> </ul> </div> </div> ); }; const AppLayout = () => { return ( <div className="App"> <Header /> </div> ); }; const root = ReactDOM.createRoot(document.getElementById("root")); root.render(<AppLayout />);
如何使用javascript forloop在点击时获取html中data-id的值并返回值
这是我的html {% if t_ques %} 今天 {% 表示 t_... 中的项目 这是我的html <ul class="conversations"> {% if t_ques %} <li class="grouping">Today</li> {% for item in t_ques %} <li class="active"> <a id="convers" class="conversation-button text-[#E8F5FC] my-2" href="{% url 'assistant:continuechat' item.pk %}" data-pk="{{item.pk}}"> <i class="fa fa-message fa-regular"></i> {{item.title| truncatewords:04 }} </a> <div class="fade"></div> <div class="edit-buttons"> <button><i class="fa fa-edit"></i></button> <button class="trash" data-id = "{{item.pk}}"><i class="fa fa-trash"></i></button> </div> </li> {% endfor %} {% endif %} {% if y_ques %} <li class="grouping">Yesterday</li> {% for item in y_ques %} <li> <a id="convers" class="conversation-button text-[#E8F5FC] my-2" href="{% url 'assistant:continuechat' item.pk %}" data-pk="{{item.pk}}"> <i class="fa fa-message fa-regular"></i> {{item.title| truncatewords:04 }} </a> <div class="fade"></div> <div class="edit-buttons"> <button><i class="fa fa-edit"></i></button> <button class="trash" data-id = "{{item.pk}}"><i class="fa fa-trash"></i></button> </div> </li> {% endfor %} {% endif %} {% if s_ques %} <li class="grouping">Previous 7 days</li> {% for item in s_ques %} <li> <a id="convers" class="conversation-button text-[#E8F5FC] my-2" href="{% url 'assistant:continuechat' item.pk %}" data-pk="{{item.pk}}"> <i class="fa fa-message fa-regular"></i> {{item.title| truncatewords:04 }} </a> <div class="fade"></div> <div class="edit-buttons"> <button><i class="fa fa-edit"></i></button> <button class="trash" data-id = "{{item.pk}}"><i class="fa fa-trash"></i></button> </div> </li> {% endfor %} {% endif %} {% if more_s_ques %} <li class="grouping">Previous 30 days</li> {% for item in more_s_ques %} <li> <a id="convers" class="conversation-button text-[#E8F5FC] my-2" href="{% url 'assistant:continuechat' item.pk %}" data-pk="{{item.pk}}"> <i class="fa fa-message fa-regular"></i> {{item.title| truncatewords:04 }} </a> <div class="fade"></div> <div class="edit-buttons"> <button><i class="fa fa-edit"></i></button> <button class="trash" data-id = "{{item.pk}}"><i class="fa fa-trash"></i></button> </div> </li> {% endfor %} {% endif %} </ul> </div> 我一直在尝试使用 JavaScript 单击时获取任何 data-pk 的值,但似乎无法实现。这一直说 currentTarget 未定义,当我用 target 替换它时,它说同样的事情。然后,如果我将其替换为 document.querySelector("#convers"),它只会给出第一个值,无论单击哪个 这是我的 JavaScript const conversationButtons = document.querySelectorAll("#convers"); conversationButtons.forEach(button => { button.addEventListener("click", getId); }); function getId(e){ var idValue = e.currentTarget.getAttribute('data-pk'); console.log(idValue); //output corresponding target-id if(!chat_id){ url = `/chat-previous/${idValue}/` }else{ url = 'initiate-chat/' } return url; } $.ajax({ type: 'POST', url: getId(), data: { message: usermsg, chatId: chat_id, // itemId: item_id, csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(), action: 'post' }, success: function(json){ const res = json['chats'] setTimeout(() => { hideTyping(); body.appendChild(mgses(res, "assistant")); scrollToBottomOfResults(); }, 1000); console.log(json) }, error: function(rs, e){ setTimeout(() => { hideTyping(); body.appendChild(setBotResponse("bot")); scrollToBottomOfResults(); }, 600); console.log(rs.error); }, }); 我使用了其他方法,例如 const getId = () => { console.log(document.querySelector(".conversation-button").getAttribute('data-pk')) if(!chat_id){ url = `/chat-previous/${document.querySelector(".conversation-button").getAttribute('data-pk')}/` }else{ url = 'initiate-chat/' } return url; } conversationButtons.forEach(button => { button.addEventListener("click", getId); console.log(button.getAttribute('data-pk')); }); 仍然无法得到我真正想要的。有什么方法可以实现这个目标吗? 委托并使用按钮的类 document.querySelector('.conversations').addEventListener('click', (e) => { let tgt = e.target.closest('.conversation-button'); if (!tgt) return; const idValue = tgt.dataset.pk; console.log(idValue); //output corresponding target-id return chat_id ? 'initiate-chat/' : `/chat-previous/${idValue}/` }) 您做出了多个错误的假设,第一个是您不能有多个具有相同 id 的元素,这将导致您描述的确切行为“它需要第一次出现的 id” 第二件事是你可能想在点击时发出ajax请求,但你构建代码的方式并不能做到这一点。 要解决这些问题,请生成如下 html button.conversation-button button.conversation-button button.conversation-button 然后向所有具有 .conversation-button 类的元素添加一个事件侦听器,并将您的 ajax 调用包装到一个函数中,主要是您已经拥有的函数。 const conversationButtons = document.querySelectorAll(".conversation-button"); conversationButtons.forEach(button => { button.addEventListener("click", doStuff); }); ... function doStuff(e) { $.ajax( ... url: getId(e) ... } function getId(e) { let idValue = e.currentTarget.getAttribute('data-pk'); let url = ...; ... return url; // } 只是一些伪代码让你得到一个想法,祝你好运:)
错误 org.apache.pig.tools.grunt.Grunt - 错误 1200:<line 16, column 46> 不匹配的输入“,”期望 LEFT_PAREN
grunt>joined_data=JOINfiltered_featuresBY(商店,日期),销售额BY(商店,日期); 2024-04-02 13:19:05,110 [主要] 错误 org.apache.pig.tools.grunt.Grunt - 错误 1200: grunt> joined_data = JOIN filtered_features BY (store, date), sales BY (store, date); 2024-04-02 13:19:05,110 [主要] 错误 org.apache.pig.tools.grunt.Grunt - 错误 1200: 不匹配的输入 ',' 期待 LEFT_PAREN 日志文件详细信息:/home/vboxuser/Documents/DDPC/EX9/q2/2/pig_1712044037517.log 猪堆栈跟踪 错误 1200:输入“,”不匹配,需要 LEFT_PAREN 解析失败:输入“,”不匹配,需要 LEFT_PAREN at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:244) at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:182) at org.apache.pig.PigServer$Graph.validateQuery(PigServer.java:1792) at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1765) at org.apache.pig.PigServer.registerQuery(PigServer.java:708) at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:1110) at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:512) at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:230) at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:205) at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:66) at org.apache.pig.Main.run(Main.java:564) at org.apache.pig.Main.main(Main.java:175) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.apache.hadoop.util.RunJar.run(RunJar.java:244) at org.apache.hadoop.util.RunJar.main(RunJar.java:158) ====================================================== ================================= 有括号但还是错误Left Paran 如果我提到列号,它就会起作用 grunt> join_data = JOIN Filtered_features BY ($0, $2), sales BY ($0, $1);
MVC ASP.NET Core Identity,创建登录、注册操作。 AuthController
公共类AuthController:控制器 { SignInManager _signInManager { 获取; } UserManager _userManager { 获取; } 角色管理器 public class AuthController : Controller { SignInManager<AppUser> _signInManager { get; } UserManager<AppUser> _userManager { get; } RoleManager<IdentityRole> _roleManager { get; } public AuthController(SignInManager<AppUser> signInManager, UserManager<AppUser> userManager, RoleManager<IdentityRole> roleManager) { _signInManager = signInManager; _userManager = userManager; _roleManager = roleManager; } public IActionResult Login() { return View(); } [HttpPost] public async Task<IActionResult> Login(string? returnUrl,LoginVM vm) { AppUser user; if (!ModelState.IsValid) { return View(vm); } if (vm.UsernameOrEmail.Contains("@")) { user = await _userManager.FindByEmailAsync(vm.UsernameOrEmail); } else { user = await _userManager.FindByNameAsync(vm.UsernameOrEmail); } if (user == null) { ModelState.AddModelError("", "Username or password is wrong"); return View(vm); } var result = await _signInManager.PasswordSignInAsync(user, vm.Password, vm.IsRemember, true); if (!result.Succeeded) { if (result.IsLockedOut) { ModelState.AddModelError("", "Too many attempts wait until " + DateTime.Parse(user.LockoutEnd.ToString()).ToString("HH:mm")); } else { ModelState.AddModelError("", "Username or password is wrong"); } return View(vm); } if (returnUrl != null) { return LocalRedirect(returnUrl); } return RedirectToAction("Index","Home"); } public IActionResult Register() { return View(); } [HttpPost] public async Task<IActionResult> Register(RegisterVM vm) { if (!ModelState.IsValid) { return View(vm); } var user = new AppUser { Fullname = vm.Fullname, Email = vm.Email, UserName = vm.Username }; var result = await _userManager.CreateAsync(user, vm.Password); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return View(vm); } var roleResult = await _userManager.AddToRoleAsync(user, Roles.Member.ToString()); if (!roleResult.Succeeded) { ModelState.AddModelError("", "Something went wrong. Please contact admin"); return View(vm); } return View(); } public async Task<IActionResult> Logout() { await _signInManager.SignOutAsync(); return RedirectToAction("Index", "Home"); } public async Task<bool> CreateRoles() { foreach (var item in Enum.GetValues(typeof(Roles))) { if (!await _roleManager.RoleExistsAsync(item.ToString())) { var result = await _roleManager.CreateAsync(new IdentityRole { Name = item.ToString() }); if (!result.Succeeded) { return false; } } } return true; } } } 所以,我在代码中搞乱了登录、注册和注销,现在这个 RoleManager 的事情让我摸不着头脑。我只是想为我的管理员用户提供一些额外的权力,但我有点不知道该怎么做。如果您能用简单的语言解释步骤或需要进行哪些更改来帮助我,那就太棒了。 我的目标是让管理员用户在我的系统中体验更好,您对此的建议非常有用。尝试了解 RoleManager 的事情以及如何为我的管理员用户提供更多能力。您直接的帮助可能会对我解决这个问题产生很大的影响! 定义管理员角色 创建管理员用户 更新注册流程: var roleResult =等待_userManager.AddToRoleAsync(用户,vm.IsAdmin? Roles.Admin.ToString() : Roles.Member.ToString()); 使用管理员角色: [授权(角色=“管理员”)] 公共 IActionResult AdminDashboard() { // 特定于管理的逻辑 } 5.提升管理能力: if (User.IsInRole("管理员")) { // 特定于管理的逻辑 } 中间件配置: services.AddIdentity() .AddRoles() .AddEntityFrameworkStores(); 7.创建角色方法: 公共无效配置(IApplicationBuilder 应用程序,IHostingEnvironment env) { // 其他中间件配置 // Create roles during application startup var authController = new AuthController(/* inject your dependencies here */); authController.CreateRoles().GetAwaiter().GetResult(); }
tailwind 应用在 tailwind 版本 3 中不起作用
我已成功安装顺风。当涉及到使用@apply时,事情就不起作用了。 我已经成功安装顺风了。当谈到使用@apply时,事情不起作用。 <body> <!-- header --> <header class="bg-transparent absolute top-0 left-0 w-full flex items-center z-10"> <div class="container"> <div class="flex items-center justify-between relative"> <div class="px-4"> <a href="#home" class="font-bold text-lg text-primary block py-6">shrlrmdh</a> </div> <div class="flex items-center px-4"> <button id="hamburger" name="hamburger" type="button" class="block absolute right-4"> <span class="hamburger-line"></span> <span class="hamburger-line"></span> <span class="hamburger-line"></span> </button> </div> </div> </div> </header> </body> 我想仅使用 @apply 指令创建一条线并旋转跨度 这是我的 tailwind css 文件,我在其中放置了 @apply 指令 @tailwind base; @tailwind components; @tailwind utilities; .hamburger-line { @apply w-[30px] h-[2px] my-2 block bg-black; } .hamburger-active > span:nth-child(1) { @apply origin-top-left rotate-45; } .hamburger-active > span:nth-child(3) { @apply origin-bottom-left -rotate-45; } ''' I've tried many methods but @apply still doesn't work. 您需要使用 tailwind @layer 指令才能使 @apply 类正常工作。 @tailwind base; @tailwind components; @tailwind utilities; @layer components { .hamburger-line { @apply w-[30px] h-[2px] my-2 block bg-black; } .hamburger-active > span:nth-child(1) { @apply origin-top-left rotate-45; } .hamburger-active > span:nth-child(3) { @apply origin-bottom-left -rotate-45; } }
以下是我的脚本: 以下是我的脚本: <?php $connection = ssh2_connect('XX.XX.XX.XX', 22); ssh2_auth_password($connection, 'root', '******'); $stream = ssh2_exec($connection, 'useradd -d /home/users/test -m testftp'); $stream = ssh2_exec($connection, 'passwd testftp'); $stream = ssh2_exec($connection, 'password'); $stream = ssh2_exec($connection, 'password'); ?> 它显示以下错误: Fatal error: Call to undefined function ssh2_connect() in /home/chaosnz/public_html/fotosnap.net/test.php on line 2 我该如何处理这个问题? 谢谢 老实说,我建议使用 phpseclib,这是一个纯 PHP SSH2 实现。示例: <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?> 它更加便携、更易于使用并且功能也更加丰富。 我已经安装了 SSH2 PECL 扩展,它工作正常,感谢大家的帮助... 我已经在 ubuntu 16.4 PHP 7.0.27-0+deb9u 和 nginx 上解决了这个问题 sudo apt install php-ssh2 您需要安装ssh2 lib sudo apt-get install libssh2-php && sudo /etc/init.d/apache2 restart 这应该足以让你上路 如果您在 OSX 上运行 bomebrew,我使用以下命令来安装它: brew install php56-ssh2 这对我有用。我从这里拉它。应该还有使用 mac 端口的 Ubuntu 和 OSX。 我正在运行 CentOS 5.6 作为我的开发环境,以下内容对我有用。 su - pecl install ssh2 echo "extension=ssh2.so" > /etc/php.d/ssh2.ini /etc/init.d/httpd restart 为了扩展 @neubert 答案,如果您使用 Laravel 5 或类似版本,您可以使用更简单的 phpseclib,如下所示: 奔跑composer require phpseclib/phpseclib ~2.0 在您的控制器中添加 use phpseclib\Net\SSH2; 然后在控制器方法中使用它,例如: $host = config('ssh.host'); $username = config('ssh.username'); $password = config('ssh.password'); $command = 'php version'; $ssh = new SSH2($host); if (!$ssh->login($username, $password)) { $output ='Login Failed'; } else{ $output = $ssh->exec($command); } 今天pecl install ssh2需要旧版本的php(<=6.0). Here https://pecl.php.net/package/ssh2您可以看到支持php7和php8的最新beta版本的ssh2。所以您应该安装其中之一: pecl install ssh2-1.3.1 * 不要忘记在 php.ini 文件中启用此 ssh2.so 扩展。 我知道有答案,但我只是在这里简化答案。 我有同样的问题,我在 ubuntu 20 中使用以下解决方案修复了它: sudo apt-get install libssh2-1 php7.1-ssh2 -y 您可以根据需要更改 php 版本,例如:php7.4-ssh2 参考:https://blog.programster.org/ubuntu-16-04-install-php-ssh2-extension 适用于 WHM 面板 菜单 > 服务器配置 > 终端: yum install libssh2-devel -y 菜单 > 软件 > 模块安装程序 PHP PECL 管理点击 ssh2 立即安装点击 菜单 > 重新启动服务 > HTTP 服务器 (Apache) 您确定要重新启动此服务吗? 是的 ssh2_connect() 工作了! 我觉得这个已有 11 年历史的讨论值得更新。我从 PHPSecLib 库切换到 PHP 7 和 8 的内置 SSH2 库,因为它似乎连接速度更快并且更标准。现在它还可以使用密钥密码,因此无需再使用第 3 方库。
在 Rails 5 中单击浏览器上的后退按钮时,带有 Select2 的表单会重复
_header.html.erb(用于表单部分) <%= form_for home_path, class: 'home', role: 'search', method: :get do |f| %> _header.html.erb(用于表单部分) <%= form_for home_path, class: 'home', role: 'search', method: :get do |f| %> <div class="form-group" style="display:inline;"> <div class="input-group input-group-md"> <%= text_field_tag :q, params[:q], placeholder: ... ,class: 'form-control hideOverflow', type: "search" %> <%= select_tag "category", options_from_collection_for_select(...),include_blank: true, class: 'form-control hideOverflow', type: "search" %> <%if logged_in? %> <%= select_tag "location", options_for_select([...], ...),class: 'form-control hideOverflow', type: "search" %> <% else %> <%= select_tag "location", options_for_select([...], ...),class: 'form-control hideOverflow', include_blank: true, type: "search" %> <% end %> <span class="input-group-addon"><%= submit_tag "Search", class: "btn-transparent"%></span> </div> </div> <% end %> JS代码 <script> $( document ).on('turbolinks:load', function() { $('select#category').select2({ width: '60%', dropdownAutoWidth : true, placeholder: "Choose a category", maximumSelectionLength: 3 }); $('select#location').select2({ width: '40%', dropdownAutoWidth : true, minimumResultsForSearch: Infinity }); }); </script> 故障或渲染问题(单击链接查看图像) 有人可以帮我解决为什么吗?另外,我的搜索表单位于标题部分文件的导航栏中。 如果我去掉脚本中的 $(...).select ,一切都会正常...我认为 select.js 有问题 在此回复: https://stackoverflow.com/a/41915129/5758027 我在自己的代码中使用了这个解决方案: $(document).on('turbolinks:before-cache', function() { // this approach corrects the select 2 to be duplicated when clicking the back button. $('.select-select2').select2('destroy'); $('.select-search-select2').select2('destroy'); } ); 和观察者: $(document).ready( ready ); //... once document ready $(document).ajaxComplete( ready ); //... once ajax is complete $(document).on('turbolinks:load', ready ); //... once a link is clicked function ready() { $(".select-search-select2").select2({ theme: "bootstrap", language: 'es', allowClear: true }); $(".select-select2").select2({ theme: "bootstrap", language: 'es', minimumResultsForSearch: Infinity, allowClear: true }); }; 总是清除缓存不是会让使用 Turbolink 变得毫无意义吗? 不如这样? $(document).on('turbolinks:before-cache', function(e) { return $('.form-control.select2').each(function() { return $(this).select2('destroy'); }); }); 我无法解决这个渲染问题(仍在等待正确的答案!),但如果有人像我一样遇到类似的问题,请尝试跳出框框思考。这是我的技巧:我在应用程序中添加了一个后退按钮。 获取完整的url路径 # get the previous url def save_previous_page session[:return_to] = request.fullpath end 仅当页面不是主页或搜索页面时才显示后退按钮 <% if session[:return_to] != request.fullpath%> <%= link_to session.delete(:return_to) || request.fullpath, class: 'back-button' do%> <i class="fa fa-arrow-circle-left" aria-hidden="true"></i> <%end%> <% end %> 同时,我仍在等待并尝试解决渲染问题... 解决了问题 只需将此代码添加到您的 .js 文件中 Turbolinks.clearCache(); 这很可能是一些资源不一致,您应该检查您的 app\views\layouts 文件夹中是否有重复声明 wither jQuery、jQuery UJS 或 Turbolinks 的文件。检查页面的所有 <script> 标签,以及是否在 layout 文件夹和内部视图中声明相同的脚本。如果情况并非如此,请检查是否有 render、yield 或 build 呼叫 简单的解决方案,不要在您不希望它运行的东西上运行 select2 构建器。 $("select#category:not(.select2-container):not(.select2-hidden-accessible)").select2(); Rails 7 更新 这里的很多东西在 Rails 7 中都不起作用,尤其是 turbolinks:before-cache 事件。您正在寻找的新事件是 turbo:before-cache 和 turbo:load,所以它看起来像这样: $(document).on("turbo:before-cache", function() { $("#select_id").select2('destroy'); }); $(document).on('turbo:load', function() { $('#select_id').select2(); });
无论我做什么,我用 Bootsrap 制作的网站右侧的空白都没有消失。如果有解决办法请告诉我 无论我做什么,我用 Bootsrap 制作的网站右侧的空白都没有消失。如果有解决办法请告诉我 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Contact | Enba Camping</title> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> <link rel="stylesheet" href="style/style.css"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> </head> <body> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> <!-- NAV --> <div class="container-fluid"> <div class="row"> <div class="col-sm-12 p-0"> <nav class="navbar navbar-expand-lg bg-body-tertiary p-0 "> <div class="container-fluid bg-dark "> <a class="navbar-brand text-light mb-2" href="index.html">Enba Camping</a> <button class="navbar-toggler btn btn-light btn btn-outline-light bg-light m-2" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon "></span> </button> <div class="collapse navbar-collapse" id="navbarNavAltMarkup"> <div class="navbar-nav ms-auto"> <a class="nav-link text-light text-center" aria-current="page" href="index.html">Home</a> <a class="nav-link text-light text-center" href="aboutus.html">About us</a> <a class="nav-link active text-light text-center" href="contact.html" aria-disabled="true">Contact</a> </div> </div> </div> </nav> </div> </div> </div> <!-- NAV END --> <!-- ABOUT US --> <div class="container-fluid p-0 bg-dark text-light"> <div class="row"> <div class="col-sm-6 ps-0"> <img src="images/lesly-derksen-F4fH5dAfZnE-unsplash.jpg" alt="" class=" d-block w-100 c-img "> </div> <div class="col-sm-6 d-flex justify-content-center align-items-center "> <div class="text-center"> <h2 class="fw-bold display-4 ">Bize Ulaşın</h2> <!-- ABOUT US --> <div class="mb-3"> <label for="exampleFormControlInput1" class="form-label">Adınız</label> <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="Name"> </div> <div class="mb-3"> <label for="exampleFormControlInput1" class="form-label">Email Adres</label> <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="Email Address"> </div> <div class="mb-3"> <label for="exampleFormControlTextarea1" class="form-label">Mesajınız</label> <textarea class="form-control" id="exampleFormControlTextarea1" placeholder="Message" rows="3"></textarea> </div> <div class=" gap-2 d-md-block "> <button class="btn btn-light " type="button">Send</button> </div> </div> </div> </div> </div> <!-- ABOUT US END --> <!-- PRODUCT --> <div class="container mt-sm-5"> <div class="row text-center "> <h1 class="d-flex justify-content-center">Mekanlarımız</h1> <hr> <div class="col-sm-4 mb-2"> <div class="card"> <img src="images/card2.jpg" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">Orman İçi Karavan Parkı</h5> <p class="card-text">Ormanın içinde konumlanan karavan parkımız, tam anlamıyla bir doğa kaçamağı sunuyor. Ormanın huzurlu atmosferinde kendinizi kaybedin. Karavanınızla konforlu bir konaklama deneyimi yaşayın.</p> <a href="#" class="btn btn-dark">Rezervasyon için tıklayınız </a> </div> </div> </div> <div class="col-sm-4 mb-2"> <div class="card"> <img src="images/card3.jpg" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">Orman İçi Çadırlı Kamp</h5> <p class="card-text">Orman içi çadırlı kamp alanımız, doğa severler için bir cennet. Gölgeli ağaçlar arasında konumlanan çadırlarımızda, kuş cıvıltıları ve huzur içinde bir konaklama deneyimi sizi bekliyor.</p> <a href="#" class="btn btn-dark">Rezervasyon için tıklayınız</a> </div> </div> </div> <div class="col-sm-4 mb-2"> <div class="card"> <img src="images/card1.jpg" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">Dağ Evi </h5> <p class="card-text">Dağ evimiz, şehrin gürültüsünden uzak,huzurlu bir konaklama imkanı sunuyor. Ferah odalarımızda dağ manzarasının keyfini çıkarabilir, gölet kenarındaki aktivitelerle vakit geçirebilirsiniz.</p> <a href="#" class="btn btn-dark">Rezervasyon için tıklayınız</a> </div> </div> </div> </div> </div> <!-- PRODUCT END --> <!-- PROJECT --> <div class="row my-4"> <div class="col-sm-12"> <h1 class="d-flex justify-content-center">Galeri</h1> <hr> </div> <div class="col-sm col-6 mb-1"><img src="images/galeri/hichem-meghachou-7I-Rj_E9ihI-unsplash.jpg" alt="" class="w-100 img-thumbnail"> </div> <div class="col-sm col-6 mb-1"><img src="images/galeri/jimmy-conover-J_XuXX9m0KM-unsplash.jpg" alt="" class="w-100 img-thumbnail"> </div> <div class="col-sm col-6 mb-1"><img src="images/galeri/josh-campbell-UbbjVyibFuc-unsplash.jpg" alt="" class="w-100 img-thumbnail"> </div> <div class="col-sm col-6 mb-1"><img src="images/galeri/shelby-cohron-ESNV6KmLJMg-unsplash.jpg" alt="" class="w-100 img-thumbnail"> </div> <div class="col-sm col-6 mb-1"><img src="images/galeri/tegan-mierle-fDostElVhN8-unsplash.jpg" alt="" class="w-100 img-thumbnail"> </div> <div class="col-sm col-6 mb-1"><img src="images/galeri/toa-heftiba-x9I-6yoXrXE-unsplash.jpg" alt="" class="w-100 img-thumbnail"> </div> </div> <!-- PROJECT END --> <!-- FOOTER --> <div class="bg-dark text-light"> <div class="container"> <footer class="pt-5 mt-5 "> <div class="row "> <div class="col-6 col-md-2 mb-3"> <h5>Section</h5> <ul class="nav flex-column "> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Home</a></li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Features</a> </li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Pricing</a> </li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">FAQs</a></li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">About</a> </li> </ul> </div> <div class="col-6 col-md-2 mb-3"> <h5>Section</h5> <ul class="nav flex-column"> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Home</a></li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Features</a> </li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Pricing</a> </li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">FAQs</a></li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">About</a> </li> </ul> </div> <div class="col-6 col-md-2 mb-3"> <h5>Section</h5> <ul class="nav flex-column"> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Home</a></li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Features</a> </li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">Pricing</a> </li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">FAQs</a></li> <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-light">About</a> </li> </ul> </div> <div class="col-md-5 offset-md-1 mb-3"> <form> <h4> Abone Ol ve Doğanın Güzelliklerini Kaçırma!</h4> <p class="fs-6">Doğanın kucaklayıcı atmosferine adım atmak, huzurla dolu anlar yaşamak ve Enba Camping'in sunduğu özel fırsatları kaçırmamak için hemen abone ol! Sitemize abone olarak, doğanın gizemli güzellikleri, özel indirimler ve etkinliklerden ilk sen haberdar olacaksın.</p> <p class="fs-6"> Unutulmaz anılar biriktirmek ve doğanın kollarında huzurlu bir deneyim yaşamak için abone ol, Enba Camping'in eşsiz dünyasına adımını at! 🏕️✨ </p> <div class="d-flex flex-column flex-sm-row w-100 gap-2"> <label for="newsletter1" class="visually-hidden">Email address</label> <input id="newsletter1" type="text" class="form-control" placeholder="Email address"> <button class="btn btn-primary" type="button">Subscribe</button> </div> </form> </div> </div> <div class="d-flex flex-column flex-sm-row justify-content-between border-top"> <p>© 2023 Company, Inc. All rights reserved.</p> <ul class="list-unstyled d-flex"> <li class="ms-3"><a class="link-body-emphasis" href="#"><svg class="bi" width="24" height="24"> <use xlink:href="#twitter"></use> </svg></a></li> <li class="ms-3"><a class="link-body-emphasis" href="#"><svg class="bi" width="24" height="24"> <use xlink:href="#instagram"></use> </svg></a></li> <li class="ms-3"><a class="link-body-emphasis" href="#"><svg class="bi" width="24" height="24"> <use xlink:href="#facebook"></use> </svg></a></li> </ul> </div> </footer> </div> </div> <!-- FOOTER END --> </body> </html> 和CSS .jumb { vertical-align: inherit; } p { font-size: 24px; } .c-item { height: 480px; } .c-img { height: 100%; object-fit: cover; filter:brightness(0.9) } 这里。我不希望页面左右移动。我想让它适合全屏,但容器结构溢出了 请将这段代码添加到您的 CSS 文件中。然后,它就会起作用。 .row{ margin-right: 0px; }
引导进度条在我的 MVC 索引视图上不起作用。 我已经用 Chrome 和 Internet Explorer 尝试过了。 @{ ViewBag.Title = "首页"; } 引导进度条在我的 MVC 索引视图上不起作用。 我已经用 Chrome 和 Internet Explorer 尝试过了。 @{ ViewBag.Title = "Home Page"; } <div class="jumbotron"> <h1>ASP.NET</h1> <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p> <p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more »</a></p> </div> <div class="row"> <div class="col-md-4"> <h2>Getting started</h2> <div class="progress-bar progress-striped "></div> </div> </div> 本次聚会迟到了,但在我使用的 Bootstrap 版本(v3.1.1)中,该类是“progress-striped”(不是像文档所说的“progress-bar-striped”),并且它和“active” ' 类必须应用于外部 div: <div class="progress progress-striped active"> <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">Some text</div> </div> 查看 CSS,选择器“progress-bar”已更改为“bar”: ./bootstrap.css: .progress { ... } .progress .bar { ... } 因此,将您的代码更改为 <div class="progress"> <div class="bar"> </div> </div> 然后就可以了。 不确定这种疯狂的原因是什么,似乎引导文档还没有更新。 <div class="progress"> <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div> </div> 这样进度动画就可以工作了。 <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;"> <span class="sr-only">60% Complete</span> </div> </div> 上面是 bootstrap v3.1.1 的代码,看起来你的进度条 div 缺少一些元素? 如果您使用 Bootstrap v4 并且需要动画,则需要使用 progress-bar-animated 而不是 active。
.navbar { 背景颜色:#F91F46; } .src-bar { 边框:0; 边框半径:5px; 概要:无; 左内边距:15px; 宽度:30vw; } .navbar { background-color: #F91F46; } .src-bar { border: 0; border-radius: 5px; outline: none; padding-left: 15px; width: 30vw; } <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" integrity="sha512-b2QcS5SsA8tZodcDtGRELiGv5SaKSk1vDHDaQRda0htPYWZ6046lr3kJ5bAAQdpV2mmA/4v0wQF9MyU6/pDIAg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js" integrity="sha512-WW8/jxkELe2CAiE4LvQfwm1rajOS8PHasCCx+knHG0gBHt8EXxS6T6tJRTGuDQVnluuAvMxWF4j8SNFDKceLFg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <nav class="navbar navbar-expand-md fixed-top"> <div class="container-fluid"> <a class="navbar-brand ms-3" href="#"> <img src="img/Logo.avif" width="40px" class="d-inline-block" /> </a> <form role="search" class="search-bar"> <div class="input-group"> <input class="src-bar" type="search" placeholder="Search For Products" /> <button class="btn bg-white" type="submit"> <i class="fa fa-search"></i> </button> </div> </form> <div class="justify-content-end"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav-colps" aria-controls="nav-colps" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="nav-colps"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li> <hr class="dropdown-divider" /> </li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </div> </nav> 切换时,我希望折叠 div 居中。我知道原因 - 我将折叠和切换 btn 放在 justify-end div 内,因为我需要切换 btn 位置位于右侧。现在,当切换时,我的折叠位于右侧,但我希望在切换时,折叠div到中心。 当我删除 justify-end div 时,它位于左侧,但如果删除它,每个导航元素都会移动到 nav 和 md 视图中 lg 的左侧。 看起来像这样或中心 我们确实需要将 .nav-collapse 移到 justify-end 元素之外,才能在较窄的视口上获得所需的布局。 要将菜单显示在右侧,请通过 flex-grow: 1 类将 .nav-collapse 应用于 flex-grow: 0 元素,覆盖 flex-grow-0 上的默认 .nav-collapse。 为了使窄视口的链接元素居中,.navbar-nav中的元素采用垂直柔性布局,因此我们可以通过align-items: center类应用align-items-center: .navbar { background-color: #F91F46; } .src-bar { border: 0; border-radius: 5px; outline: none; padding-left: 15px; width: 30vw; } <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" integrity="sha512-b2QcS5SsA8tZodcDtGRELiGv5SaKSk1vDHDaQRda0htPYWZ6046lr3kJ5bAAQdpV2mmA/4v0wQF9MyU6/pDIAg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js" integrity="sha512-WW8/jxkELe2CAiE4LvQfwm1rajOS8PHasCCx+knHG0gBHt8EXxS6T6tJRTGuDQVnluuAvMxWF4j8SNFDKceLFg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <nav class="navbar navbar-expand-md fixed-top"> <div class="container-fluid"> <a class="navbar-brand ms-3" href="#"> <img src="https://picsum.photos/40/40" width="40px" class="d-inline-block" /> </a> <form role="search" class="search-bar"> <div class="input-group"> <input class="src-bar" type="search" placeholder="Search For Products" /> <button class="btn bg-white" type="submit"> <i class="fa fa-search"></i> </button> </div> </form> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav-colps" aria-controls="nav-colps" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse flex-grow-0" id="nav-colps"> <ul class="navbar-nav me-auto mb-2 mb-lg-0 align-items-center"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li> <hr class="dropdown-divider" /> </li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </nav> 您还可以考虑通过 text-align: center 类应用 text-center,将链接元素 text 居中: .navbar { background-color: #F91F46; } .src-bar { border: 0; border-radius: 5px; outline: none; padding-left: 15px; width: 30vw; } <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" integrity="sha512-b2QcS5SsA8tZodcDtGRELiGv5SaKSk1vDHDaQRda0htPYWZ6046lr3kJ5bAAQdpV2mmA/4v0wQF9MyU6/pDIAg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js" integrity="sha512-WW8/jxkELe2CAiE4LvQfwm1rajOS8PHasCCx+knHG0gBHt8EXxS6T6tJRTGuDQVnluuAvMxWF4j8SNFDKceLFg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <nav class="navbar navbar-expand-md fixed-top"> <div class="container-fluid"> <a class="navbar-brand ms-3" href="#"> <img src="https://picsum.photos/40/40" width="40px" class="d-inline-block" /> </a> <form role="search" class="search-bar"> <div class="input-group"> <input class="src-bar" type="search" placeholder="Search For Products" /> <button class="btn bg-white" type="submit"> <i class="fa fa-search"></i> </button> </div> </form> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav-colps" aria-controls="nav-colps" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse flex-grow-0" id="nav-colps"> <ul class="navbar-nav me-auto mb-2 mb-lg-0 text-center"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li> <hr class="dropdown-divider" /> </li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </nav>
ASP.NET MVC 项目模板在移动设备上无法调整为 100%
我不明白为什么 Web .Net MVC 项目上的默认模板没有在移动设备中调整为 100% 宽度。 我在视图上使用数据表: @模型IEnumerable 我不明白为什么 Web .Net MVC 项目上的默认模板没有在移动设备中调整为 100% 宽度。 我在视图上使用数据表: @model IEnumerable<iziConference.Models.EventAttendee> <h2>Participantes.</h2> <br /> <button><a style="text-decoration: none" href='@Url.Action("Create", new { eventId = ViewBag.EventId })'>Criar Participante</a></button> <button id="at-btn-refresh"> Actualizar</button> <input id="eventId" type="hidden" value="@ViewBag.EventId"> <table id="at-attendees-list" cellpadding="10" border="1" class="row-border stripe"> <thead> <tr> <th>ID</th> <th>Tipo</th> <th>Nome</th> <th>Email</th> <th>Estado </th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr id="[email protected]_Id"> <td style="padding: 5px"> @Html.DisplayFor(modelItem => item.Attendee.Id) </td> <td> @Html.DisplayFor(modelItem => item.AttendeeType) </td> <td> @Html.DisplayFor(modelItem => item.Attendee.Name) </td> <td> @Html.DisplayFor(modelItem => item.Attendee.Email) </td> <td> @if (item.IsActive) { <button id="[email protected]_Id" class="at-btn-active-state active" data-attendee-id="@item.Attendee_Id" data-attendee-name="@item.Attendee.Name" data-active-new-state="false" data-show-confirmation-alert="true">Desactivar</button> } else { <button id="[email protected]_Id" class="at-btn-active-state inactive" data-attendee-id="@item.Attendee_Id" data-attendee-name="@item.Attendee.Name" data-active-new-state="true" data-show-confirmation-alert="true">Activar</button> } </td> </tr> } </tbody> </table> 由脚本加载: var _atteendeesList = "at-attendees-list"; $("#" + _atteendeesList).DataTable({ "paging": false, "info": false, "language": { "search": "Pesquisar:", "info": "Participantes inscritos: _PAGES_" } }); 使用默认的_Layout.cshtml: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>izigo Conference - Gestor de Conteúdos</title> <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> <meta name="viewport" content="width=device-width" /> @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") </head> <body> <header> <div class="content-wrapper"> <section id="login"> @Html.Partial(MVC.Account.Views._LoginPartial) </section> <div style="padding: 10px;"> @if (Request.IsAuthenticated) { <nav> <ul id="menu"> <li>@Html.ActionLink("Home", MVC.Home.Index())</li> <li>@Html.ActionLink("Participantes", MVC.Attendee.Index())</li> <li>@Html.ActionLink("Check-in", MVC.Checkin.Index())</li> </ul> </nav> } </div> </div> </header> <div id="body"> @RenderSection("featured", required: false) <section class="content-wrapper main-content clear-fix"> @RenderBody() </section> </div> <footer style="padding-left: 25px;"> <div class="content-wrapper"> <div class="float-left"> <p>© @DateTime.Now.Year - <a href="https://www.izigo.pt/conference" target="_blank">izigo Conference</a> - <i>Powered by</i><a href="https://www.izigo.pt" target="_blank">izigo.pt</a></p> </div> </div> </footer> @Scripts.Render("~/bundles/jquery", "~/bundles/iziconference") @RenderSection("scripts", required: false) </body> </html> 研究了 dataTables 库的选项后,我找到了一个创建响应式解决方案的选项: 我已经包含了响应表结构和columnDefs的选项,以选择哪些选项在移动设备中保持可见: $("#" + _atteendeesList).DataTable({ "responsive": true, "columnDefs": [ { responsivePriority: 1, targets: 0 }, { responsivePriority: 2, targets: -1 } ], "paging": false, "info": false, "language": { "search": "Pesquisar:", "info": "Participantes inscritos: _PAGES_" } }); 我还必须在捆绑包中包含数据表扩展的 js 和 css 响应式库(可在此处下载:https://datatables.net/download/): bundles.Add(new ScriptBundle("~/bundles/iziconference").Include( "~/Content/Scripts/datatables.min.js", "~/Content/Scripts/dataTables.responsive.min.js")); // add-on bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/Styles/datatables.min.css", "~/Content/Styles/responsive.dataTables.min.css"));
错误:在此 BlocBuilder<InternetBloc> Widget<InternetBloc, InternetState> 上方找不到正确的提供程序
我在尝试将 flutter_bloc 集成到 flutter 项目中时遇到错误。 错误:在此 BlocBuilder 上方找不到正确的 Provider 我在尝试将 flutter_bloc 集成到 flutter 项目中时遇到错误。 错误:在此 BlocBuilder Widget 上方找不到正确的提供者 这是我正在使用的代码示例。 internet_state.dart abstract class InternetState{} class InitialInternetState extends InternetState{} class LostConnectionInternetState extends InternetState{} class GainConnectionInternetState extends InternetState{} internet_event.dart abstract class InternetEvent{} class LostConnectionEvent extends InternetEvent{} class GainConnectionEvent extends InternetEvent{} internet_bloc.dart class InternetBloc extends Bloc<InternetEvent, InternetState>{ final Connectivity _connectivity = Connectivity(); StreamSubscription? streamSubscription; InternetBloc() : super(InitialInternetState()){ on<GainConnectionEvent>((event, emit) => emit(GainConnectionInternetState())); on<LostConnectionEvent>((event, emit) => emit(LostConnectionInternetState())); _connectivity.onConnectivityChanged.listen((event) { if(event == ConnectivityResult.mobile || event == ConnectivityResult.wifi){ add(GainConnectionEvent()); } else { add(LostConnectionEvent()); } }); } @override Future<void> close() { streamSubscription?.cancel(); return super.close(); } } main.dart class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(title),), body: SafeArea( child: Center(child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, )), ),); } } 我明白了。 ======== 小部件库捕获异常====================================== =================== 构建 MediaQuery(MediaQueryData(size: Size(392.7, 783.3), devicePixelRatio: 2.8, textScaler: noscaling, platformBrightness: Brightness.light, padding: EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets 时抛出以下 ProviderNotFoundException。零,systemGestureInsets:EdgeInsets(29.8,24.0,29.8,8.0),alwaysUse24HourFormat:假,accessibleNavigation:假,highContrast:假,onOffSwitchLabels:假,disableAnimations:假,invertColors:假,boldText:假,navigationMode:传统,gestureSettings:DeviceGestureSettings (touchSlop:8.0),显示功能:[])): 错误:无法在此 BlocBuilder Widget 之上找到正确的提供程序 发生这种情况是因为您使用了不包含提供程序的 BuildContext 你的选择。有以下几种常见场景: 您在main.dart中添加了一个新的提供程序并执行了热重载。 要修复此问题,请执行热重启。 您尝试阅读的提供商处于不同的路线。 提供商具有“范围”。因此,如果您在路线中插入提供者,那么 其他路线将无法访问该提供商。 您使用了 BuildContext,它是您尝试读取的提供程序的祖先。 确保 BlocBuilder 位于您的 MultiProvider/Provider 下。 当您创建提供程序并尝试立即读取它时,通常会发生这种情况。 例如,代替: Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // Will throw a ProviderNotFoundError, because `context` is associated // to the widget that is the parent of `Provider<Example>` child: Text(context.watch<Example>().toString()), ); } 考虑使用builder,如下所示: Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // we use `builder` to obtain a new `BuildContext` that has access to the provider builder: (context, child) { // No longer throws return Text(context.watch<Example>().toString()); } ); } 如果这些解决方案都不起作用,请考虑在 StackOverflow 上寻求帮助: https://stackoverflow.com/questions/tagged/flutter The relevant error-causing widget was: SafeArea SafeArea:file:///Users/../Projects/flutterTest/bloc_test/lib/main.dart:37:13 When the exception was thrown, this was the stack: #0 Provider._inheritedElementOf (package:provider/src/provider.dart:343:7) #1 Provider.of (package:provider/src/provider.dart:293:30) #2 ReadContext.read (package:provider/src/provider.dart:649:21) #3 _BlocBuilderBaseState.initState (package:flutter_bloc/src/bloc_builder.dart:130:36) #4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5602:55) #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5) ... Normal element mounting (4 frames) #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16) #10 Element.updateChild (package:flutter/src/widgets/framework.dart:3831:20) #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #12 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #13 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #14 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #15 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #16 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #18 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #19 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #20 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #21 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #22 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #23 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #25 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #26 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #27 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #28 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #30 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #31 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #32 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #34 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #35 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #37 Element.updateChildren (package:flutter/src/widgets/framework.dart:3964:32) #38 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6896:17) #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #41 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #42 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #43 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #44 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #45 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #46 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #47 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #48 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #49 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #50 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #51 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #52 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #53 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #54 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #55 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #56 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #57 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #58 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #59 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #60 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #61 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #62 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #63 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #64 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #66 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #67 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #68 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #69 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #70 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #71 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #72 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #73 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #74 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #75 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #76 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #77 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #78 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #79 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #80 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #81 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #82 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #83 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #84 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #85 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #86 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #87 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #88 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #89 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #90 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #91 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #92 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #93 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #94 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #95 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #96 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #97 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #98 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #99 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #100 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #101 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #102 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #103 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #104 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #105 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #106 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #107 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #108 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #109 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2895:19) #110 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:984:21) #111 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5) #112 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15) #113 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9) #114 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:978:7) #118 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12) (elided 3 frames from class _Timer and dart:async-patch) ==================================================================================================== 我不想使用像 MultiProvider 这样的全局提供程序。 您应该在某处创建 InternetBloc 并提供它。 MultiProvider 本身并不是全局的,它只是多个。 更多信息在这里:https://bloclibrary.dev/#/flutterbloccoreconcepts?id=blocprovider 所以,如果您不想使用全局提供程序,它将看起来像这样: class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), body: SafeArea( child: Center( child: BlocProvider<InternetBloc>( create: ( context) => InternetBloc(), child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, ), ), ), ), ); } } 要使用 BlocBuilder,您需要在 Widget 树中放置一个 BlocProvider。最佳实践是将其放置得尽可能深。在您的情况下,只需将 BlocProvider 放在 BlocBuilder 之上。 此外 MultiProvider / MultiBlocProvider 不是全局 Provider。它只是一个提供多个 Provider/BlocProvider 的便捷小部件。 class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), body: SafeArea( child: Center( // Now everything below that can access the InternetBloc child: BlocProvider<InternetBloc>( create: (_) => InternetBloc(), child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, ), ), ), ), ); } }