深入解析 Cypress 基础命令:从入门到实战的全面指南

作为前端开发者或测试工程师,我们在构建现代 Web 应用时,最担心的往往是:“我的代码改动会不会导致原有功能崩溃?”或者“这种手动点击测试太枯燥了,有没有更高效的方法?” Cypress 作为一款现代化的端到端(E2E)测试框架,正是为了解决这些痛点而生。它不仅运行速度快,而且由于它直接运行在浏览器内部,能够让我们像编写业务代码一样自然地编写测试脚本。

在这篇文章中,我们将深入探讨 Cypress 的核心基础命令。我们将不仅仅满足于“知道怎么用”,而是通过实际的代码示例,去理解这些命令背后的工作原理、最佳实践以及如何规避常见的陷阱。让我们带着问题出发,一起探索如何利用 Cypress 让我们的应用更加健壮。

什么是 Cypress 命令?

在开始写代码之前,我们需要先理解 Cypress 的“命令”到底意味着什么。不同于传统的测试工具(如 Selenium)仅提供简单的 API 调用,Cypress 的命令是经过精心设计的,旨在让我们能够以“链式调用”的方式构建测试场景。

你可以把这些命令想象成一系列与浏览器对话的指令。当你写下 INLINECODE648c9580 时,你在告诉 Cypress:“去帮我在 DOM 树里找个东西”;当你接着写 INLINECODE6b913eab 时,你在说:“找到后,帮我点击它”。

最核心的概念在于,Cypress 的命令是异步的。这意味着即使你的代码看起来是同步的(一行接一行),Cypress 也会自动处理等待和重试机制,直到元素出现或者超时。这种设计极大地减少了我们需要编写 INLINECODE0ac6fa72 或 INLINECODEdc01b1e4 代码的次数,让测试脚本更加稳定、可读性更强。我们将按照功能类别,详细拆解这些命令的用法。

页面导航与控制

1. cy.visit():开启测试的第一步

任何 E2E 测试都需要一个起点。INLINECODEf64bb15d 是我们打开网页的入口。它的作用不仅仅是导航到 URL,它还会等待页面完全加载(直到 INLINECODE84fca6ab 事件触发)。

基本用法:

cy.visit(‘https://example.com/login‘)

进阶应用与选项:

在实际项目中,我们可能需要在访问页面时模拟特定的环境,比如处理 HTTP 基本认证,或者控制页面加载超时的时间。

cy.visit(‘/profile‘, {
  auth: {
    username: ‘testUser‘,
    password: ‘secretPassword‘
  },
  timeout: 30000, // 如果网络环境差,可以将默认 60s 的超时时间调整得更长或更短
  onBeforeLoad: (contentWindow) => {
    // 在页面的所有资源加载之前执行,可以用于注入修改 window 对象
    Object.defineProperty(contentWindow.navigator, ‘language‘, { value: ‘zh-CN‘ });
  }
})

2. cy.reload():刷新页面

有时候我们需要测试页面在刷新后状态是否保持,或者重新加载数据。cy.reload() 就像浏览器的刷新按钮一样简单。

cy.reload()

// 强制刷新,清除缓存(等同于 Ctrl+F5 或 Cmd+Shift+R)
cy.reload(true)

3. cy.go():模拟浏览器前进后退

虽然不如前两个常用,但 cy.go() 允许我们控制浏览器的历史记录堆栈。

cy.go(‘back‘)  // 后退一页
cy.go(-1)      // 效果同上
cy.go(‘forward‘) // 前进一页

核心选择器:定位 DOM 元素

选择元素是编写测试最关键的一步。如果选错了元素,测试就会失败或者误判。Cypress 使用 jQuery 的选择器引擎,这意味着几乎所有你能在 jQuery 中使用的 CSS 选择器在这里都适用。

4. cy.get():通用的元素选择器

cy.get() 是最常用的命令,它允许你通过 CSS 选择器查找元素。

cypress.get(‘.btn-submit‘)          // 类选择器
cy.get(‘#username‘)                // ID 选择器
cy.get(‘input[name="email"]‘)     // 属性选择器

实战技巧与最佳实践:

  • 优先使用 INLINECODE5fa02928 属性: 在生产代码中,CSS 类名(如 INLINECODE04fbc33f)可能会因为 UI 框架重构(如 Tailwind 或 CSS Modules)而频繁变化,导致测试脆弱。我们强烈建议添加专门给测试用的属性。
    
    
    
    // 这样即使 CSS 类名改了,测试依然有效
cy.get(‘[data-cy="submit-btn"]‘)
    
  • 避免使用过于宽泛的选择器: 尽量不要只用 INLINECODEca6342e5 或 INLINECODE3c200156,因为页面上通常会有很多个这样的元素,这会导致 Cypress 找不到唯一的目标或者误操作。

5. cy.contains():按内容查找

当我们想根据元素的文本内容来定位它时,cy.contains() 非常好用。它会查找包含特定文本的元素。

// 查找包含“Submit”文本的元素(无论它是 button 还是 span)
cy.contains(‘Submit‘).click()

// 使用正则表达式进行模糊匹配
// 例如,查找包含“Welcome”且后面跟着数字的文本
cy.contains(/Welcome \d+/)

用户交互模拟:点击与输入

定位到元素后,我们需要模拟用户的真实操作。

6. cy.click():模拟点击事件

这是测试中最常见的交互。

cy.get(‘button‘).click()

// 我们可以传递选项,比如模拟按住 Shift 键点击
cy.get(‘a‘).click({ shiftKey: true, multiple: true })

实战场景:处理弹窗和隐藏元素

有时候按钮被另一个元素遮挡,或者 CSS 设置了 INLINECODE8bef922f,直接点击会报错。虽然 Cypress 会自动尝试滚动到元素可见,但如果你强制点击,可以使用 INLINECODEc43acb5b。

cy.get(‘.hidden-checkbox‘).check({ force: true })

7. cy.type():模拟键盘输入

用于在 INLINECODEd2a3400c 或 INLINECODEaf41bc34 中输入内容。

cy.get(‘input[name="email"]‘).type(‘[email protected]‘)

实用细节:

INLINECODE7203204b 命令非常智能。如果你在输入框中已经有内容,再次使用 INLINECODE33aeb273 会在现有文本后面追加。如果你希望先清空再输入,可以使用 INLINECODE3b257cee 来加速输入,或者配合 INLINECODE23361a48 使用。

cy.get(‘#query‘).type(‘Hello‘).type(‘ World‘) // 结果是 "Hello World"

// 模拟特殊按键
cy.get(‘#search‘).type(‘search text{enter}‘) // 输入后按回车

8. cy.clear():清空输入框

这是一个便捷命令,相当于选中输入框的所有文本并按删除键。

cy.get(‘#username‘).type(‘wrongName‘).clear().type(‘correctName‘)

断言与验证:确保结果正确

测试的核心在于“验证”。如果没有断言,我们就无法知道功能是否正常。Cypress 集成了 Chai 和 Chai-Sinon,让断言变得非常自然。

9. cy.should():显式断言

这是最常用的断言方式。它允许我们断言当前元素的状态、属性或文本。

cy.get(‘.error-message‘)
  .should(‘be.visible‘) // 断言元素是可见的
  .and(‘have.class‘, ‘alert-error‘) // 链式断言:必须包含特定类名
  .and(‘contain‘, ‘登录失败‘) // 文本包含“登录失败”

实战技巧:重试机制的理解

INLINECODE87d0af9b 命令会自动重试。如果你的应用是异步加载数据的(比如 AJAX 请求),Cypress 会不断检查条件,直到断言通过或超时。这避免了我们需要写大量的 INLINECODE41c715f3 等待代码。

10. 隐式断言:url() 与 title()

除了对元素进行断言,我们还需要对页面的全局状态进行验证。

#### cy.url()

用于获取或断言当前页面的 URL。

cy.url().should(‘include‘, ‘/dashboard‘)
cy.url().should(‘eq‘, ‘https://example.com/profile/settings‘)

#### cy.title()

用于获取或断言 </code> 标签的内容。</p> <pre><code>cy.title().should(‘eq‘, ‘User Profile | My Website‘) </code></pre> <h2><span id="i-4">高级控制:等待、网络请求与调试</span></h2> <p>在复杂的单页应用(SPA)中,我们需要处理异步请求的响应时间差,或者直接控制网络层。</p> <h3>11. cy.wait():精准的等待策略</h3> <p><strong>警告:</strong> 在初学者的测试中,INLINECODE<em>4ded2be7(固定等待时间)经常被滥用。这会让测试变得极慢且不稳定。<strong>尽量避免使用固定时间的等待</strong>。INLINECODE</em>8b26c50a 的真正威力在于等待 <strong>别名(Aliases)</strong> 的网络请求。<br /> <strong>最佳实践示例:</strong></p> <p>假设点击“保存”按钮会触发一个 <code>/api/save</code> 的 POST 请求。我们不能仅仅依靠 DOM 变化来判断完成,而是应该等待服务器响应。</p> <pre><code>// 1. 定义拦截器并设置别名cy.intercept(‘POST‘, ‘/api/save‘).as(‘saveRequest‘) // 2. 执行操作 cy.get(‘.save-btn‘).click() // 3. 等待特定的响应完成,而不是盲等5秒 cy.wait(‘@saveRequest‘).then((interception) => { // 我们甚至可以在这里检查响应的状态码或返回数据 expect(interception.response.statusCode).to.eq(201) }) </code></pre> <h3>12. cy.intercept():网络请求的拦截与 Mock</h3> <p>这是 Cypress 中最强大的命令之一(以前叫 <code>cy.route</code>,已被取代)。它允许我们监视、修改或模拟 XHR/Fetch 请求。这对于测试边缘情况(例如服务器报错、慢速网络)非常有用。</p> <p><strong>场景 1:模拟错误响应</strong></p> <p>我们要测试当服务器返回 500 错误时,应用是否显示错误提示。</p> <pre><code>cy.intercept(‘GET‘, ‘/api/user/profile‘, { statusCode: 500, body: { error: ‘Server Error‘ }, forceNetworkError: false // 模拟网络完全断口设置为 true }).as(‘getError‘) cy.visit(‘/profile‘) cy.wait(‘@getError‘) cy.get(‘.error-toast‘).should(‘be.visible‘) </code></pre> <p><strong>场景 2:模拟慢速网络</strong></p> <p>测试加载动画是否正常显示。</p> <pre><code>cy.intercept(‘GET‘, ‘/api/heavy-data‘, { delay: 2000, // 延迟 2 秒返回 fixture: ‘data.json‘ // 从 fixture 文件读取返回数据 }).as(‘slowRequest‘) cy.visit(‘/page‘) // 断言加载动画存在 cy.get(‘.spinner‘).should(‘be.visible‘) // 等待数据返回后,断言加载动画消失 cy.wait(‘@slowRequest‘) cy.get(‘.spinner‘).should(‘not.exist‘) </code></pre> <h3>13. cy.request():无需页面的 API 测试</h3> <p>有时我们只需要测试 API 接口本身,不需要加载浏览器页面(这会更快)。<code>cy.request</code> 允许我们发送 HTTP 请求并验证响应。</p> <pre><code>cy.request(‘POST‘, ‘https://api.example.com/login‘, { username: ‘admin‘, password: ‘123456‘ }).then((response) => { expect(response.status).to.eq(200) expect(response.body).to.have.property(‘token‘) }) </code></pre> <h2><span id="i-5">总结:编写健壮测试的关键要点</span></h2> <p>通过这一系列的探索,我们可以看到 Cypress 不仅仅是一个简单的自动化工具,它是一套完整的测试生态系统。让我们回顾一下构建高质量测试的几个核心原则:</p> <ul> <li> <strong>不要依赖固定等待:</strong> 尽量使用 INLINECODE<em>2d0e8be9 配合 INLINECODE</em>56982667 来处理异步操作,或者利用 Cypress 自动等待 DOM 重绘的特性。滥用 <code>cy.wait(1000)</code> 是最糟糕的做法。</li> </ul> <ul> <li> <strong>使用 <code>data-cy</code> 属性:</strong> 将你的测试选择器与 CSS 样式解耦,这样前端 UI 的重构就不会轻易破坏你的测试代码。</li> </ul> <ul> <li> <strong>测试用户行为,而非实现细节:</strong> 我们应该关注“用户点击了什么”和“用户看到了什么”,而不是“这个函数是否被调用”。例如,与其断言一个类名是否存在(INLINECODE<em>a05479b2),不如断言该元素是否可见(INLINECODE</em>e4db976c),因为类名只是实现“可见”的一种手段。</li> </ul> <ul> <li> <strong>善用 Fixture 和 Intercept:</strong> 对于依赖后端数据的测试,使用 INLINECODE<em>2b4bfd1a 和 INLINECODE</em>c931b964 来控制数据输入,这样可以确保每次测试的环境都是一致的,不会因为后台脏数据而随机失败。</li> </ul> <p>掌握这些基础命令后,你已经能够覆盖 Web 应用中 80% 的常见场景了。下一步,我们建议你尝试将这些命令组合成更复杂的“自定义命令”(Custom Commands),以此来封装你们项目中特有的业务逻辑,让你的测试代码更加整洁、复用性更高。祝你在 Cypress 的测试之旅中,写出更加稳定、高效的代码!</p> </div> <footer class="kratos-entry-footer clearfix"> <div class="post-note">声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。如需转载,请注明文章出处豆丁博客和来源网址。<a href="https://shluqu.cn/30994.html">https://shluqu.cn/30994.html</a></div> <div class="ph-item"> <div class="ph-col-12"> <div class="ph-rosd"> <div class="ph-col-6 big"> <div class="post-like-donate text-center clearfix" id="post-like-donate"> <a href="javascript:;" id="btn" data-action="love" data-id="30994" class="Love "><i class="fa fa-thumbs-o-up"></i> 点赞</a> <a href="javascript:;" class="Share"><i class="fa fa-share-alt"></i> 分享</a> <div class="share-wrap" style="display: none;"> <div class="share-group"> <a href="javascript:;" class="share-plain twitter" onclick="share('qq');" rel="nofollow"> <div class="icon-wrap"> <i class="fa fa-qq"></i> </div> </a> <a href="javascript:;" class="share-plain weibo" onclick="share('weibo');" rel="nofollow"> <div class="icon-wrap"> <i class="fa fa-weibo"></i> </div> </a> <a href="javascript:;" class="share-plain facebook style-plain" onclick="share('facebook');" rel="nofollow"> <div class="icon-wrap"> <i class="fa fa-facebook"></i> </div> </a> <a href="javascript:;" class="share-plain weixin pop style-plain" rel="nofollow"> <div class="icon-wrap"> <i class="fa fa-weixin"></i> </div> </a> <div class="share-int"> <div class="qrcode" data-url="https://shluqu.cn/30994.html"></div> <p>打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮</p> </div> </div> <script type="text/javascript"> function share(obj){ var qqShareURL="http://connect.qq.com/widget/shareqq/index.html?"; var weiboShareURL="http://service.weibo.com/share/share.php?"; var facebookShareURL="https://www.facebook.com/sharer/sharer.php?"; var twitterShareURL="https://twitter.com/intent/tweet?"; var host_url="https://shluqu.cn/30994.html"; var title='%E3%80%90%E6%B7%B1%E5%85%A5%E8%A7%A3%E6%9E%90%20Cypress%20%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4%EF%BC%9A%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E6%88%98%E7%9A%84%E5%85%A8%E9%9D%A2%E6%8C%87%E5%8D%97%E3%80%91'; var qqtitle='%E3%80%90%E6%B7%B1%E5%85%A5%E8%A7%A3%E6%9E%90%20Cypress%20%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4%EF%BC%9A%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E6%88%98%E7%9A%84%E5%85%A8%E9%9D%A2%E6%8C%87%E5%8D%97%E3%80%91'; var excerpt='%E4%BD%9C%E4%B8%BA%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91%E8%80%85%E6%88%96%E6%B5%8B%E8%AF%95%E5%B7%A5%E7%A8%8B%E5%B8%88%EF%BC%8C%E6%88%91%E4%BB%AC%E5%9C%A8%E6%9E%84%E5%BB%BA%E7%8E%B0%E4%BB%A3%20Web%20%E5%BA%94%E7%94%A8%E6%97%B6%EF%BC%8C%E6%9C%80%E6%8B%85%E5%BF%83%E7%9A%84%E5%BE%80%E5%BE%80%E6%98%AF%EF%BC%9A%E2%80%9C%E6%88%91%E7%9A%84%E4%BB%A3%E7%A0%81%E6%94%B9%E5%8A%A8%E4%BC%9A%E4%B8%8D%E4%BC%9A%E5%AF%BC%E8%87%B4%E5%8E%9F%E6%9C%89%E5%8A%9F%E8%83%BD%E5%B4%A9%E6%BA%83%EF%BC%9F%E2%80%9D%E6%88%96%E8%80%85%E2%80%9C%E8%BF%99%E7%A7%8D%E6%89%8B%E5%8A%A8%E7%82%B9%E5%87%BB%E6%B5%8B%E8%AF%95%E5%A4%AA%E6%9E%AF%E7%87%A5%E4%BA%86%EF%BC%8C%E6%9C%89%E6%B2%A1%E6%9C%89%E6%9B%B4%E9%AB%98%E6%95%88%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9F%E2%80%9D%20Cypress%20%E4%BD%9C%E4%B8%BA%E4%B8%80%E6%AC%BE%E7%8E%B0%E4%BB%A3%E5%8C%96%E7%9A%84%E7%AB%AF%E5%88%B0%E7%AB%AF%EF%BC%88E2E%EF%BC%89%E2%80%A6%E2%80%A6'; var wbexcerpt='%E4%BD%9C%E4%B8%BA%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91%E8%80%85%E6%88%96%E6%B5%8B%E8%AF%95%E5%B7%A5%E7%A8%8B%E5%B8%88%EF%BC%8C%E6%88%91%E4%BB%AC%E5%9C%A8%E6%9E%84%E5%BB%BA%E7%8E%B0%E4%BB%A3%20Web%20%E5%BA%94%E7%94%A8%E6%97%B6%EF%BC%8C%E6%9C%80%E6%8B%85%E5%BF%83%E7%9A%84%E5%BE%80%E5%BE%80%E6%98%AF%EF%BC%9A%E2%80%9C%E6%88%91%E7%9A%84%E4%BB%A3%E7%A0%81%E6%94%B9%E5%8A%A8%E4%BC%9A%E4%B8%8D%E4%BC%9A%E5%AF%BC%E8%87%B4%E5%8E%9F%E6%9C%89%E5%8A%9F%E8%83%BD%E5%B4%A9%E6%BA%83%EF%BC%9F%E2%80%9D%E6%88%96%E8%80%85%E2%80%9C%E8%BF%99%E7%A7%8D%E6%89%8B%E5%8A%A8%E7%82%B9%E5%87%BB%E6%B5%8B%E8%AF%95%E5%A4%AA%E6%9E%AF%E7%87%A5%E4%BA%86%EF%BC%8C%E6%9C%89%E6%B2%A1%E6%9C%89%E6%9B%B4%E9%AB%98%E6%95%88%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9F%E2%80%9D%20Cypress%20%E4%BD%9C%E4%B8%BA%E4%B8%80%E6%AC%BE%E7%8E%B0%E4%BB%A3%E5%8C%96%E7%9A%84%E7%AB%AF%E5%88%B0%E7%AB%AF%EF%BC%88E2E%EF%BC%89%E2%80%A6%E2%80%A6'; var pic=""; var _URL; if(obj=="qq"){ _URL=qqShareURL+"url="+host_url+"&title="+qqtitle+"&pics="+pic+"&desc=&summary="+excerpt+"&site=vtrois"; }else if(obj=="weibo"){ _URL=weiboShareURL+"url="+host_url+"&title="+title+wbexcerpt+"&pic="+pic; }else if(obj=="facebook"){ _URL=facebookShareURL+"u="+host_url; }else if(obj=="twitter"){ _URL=twitterShareURL+"text="+title+excerpt+"&url="+host_url; } window.open(_URL); } </script> </div> </div> </div> <div class="ph-col-6 big"> <div class="post-ratings" data-post="30994"> <div class="rating" data-post="30994" data-rating="0" data-readonly="0"style="text-align: center;color: #FFD700;"></div> <div class="rating-meta" style="text-align: center;"> <strong>0.00</strong> 平均评分 (<strong>0</strong>% 分数) - <strong class="votes">0</strong> 票 </div> </div></div> </div> </div> </div> <div class="footer-tag clearfix"> <div class="pull-left"> <i class="fa fa-tags"></i> </div> </div> </footer> </div> <nav class="navigation post-navigation clearfix" role="navigation"> <div class="nav-previous clearfix"> <a title="Java 中 List 与 Set 的终极指南:2026 年架构师视角的深度解析" href="https://shluqu.cn/30992.html">< 上一篇</a> </div> <div class="nav-next"> <a title="产品市场契合度 (PMF) 深度指南:2026年的技术视角与实践" href="https://shluqu.cn/30995.html">下一篇 ></a> </div> </nav><br /> <div class="obs-heng-link"> <h3 class="obs-heng-a"><i class="fa fa-share-alt" aria-hidden="true"></i>相关文章<span class="section-h3-more-link"><i class="fa fa-volume-up" aria-hidden="true" style="color:#ec004a;"></i><a href="/7811.html">美国1G带宽/1T流量高速vps $17.99/年</a></span> </h3> </div> <div id="respond" class="comment-respond"> <div id="recent-content"> <div id="zazhi-2-home-block-one-5" class="widget-zazhi-2-home-block-one"> <div class="content-block content-block-1 clear"> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34667.html" title="深入解析 Java Vector 的 add() 方法:从基础到实战进阶">深入解析 Java Vector 的 add() 方法:从...</a> </div> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34666.html" title="深入理解 SOAR:安全编排、自动化与响应的完全指南">深入理解 SOAR:安全编排、自动化与响应的...</a> </div> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34665.html" title="Tailwind CSS Justify Content 详解:精通弹性布局的主轴对齐">Tailwind CSS Justify Content 详解:精通...</a> </div> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34664.html" title="Java 微服务面试全解析:面向 2026 的架构演进与实战指南">Java 微服务面试全解析:面向 2026 的架构...</a> </div> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34663.html" title="深入理解 Java 反射机制:原理、实践与性能优化">深入理解 Java 反射机制:原理、实践与性...</a> </div> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34662.html" title="如何备份您的 Android 设备?">如何备份您的 Android 设备?</a> </div> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34661.html" title="电子元器件深度解析:2026年视角下的基石与前沿">电子元器件深度解析:2026年视角下的基石...</a> </div> <div class="post-list-1 hentry "><a rel="bookmark" href="https://shluqu.cn/34660.html" title="深入理解回溯法:如何高效生成数组的所有子集">深入理解回溯法:如何高效生成数组的所有子集</a> </div> </div> </div> </div> </div> <div id="comments" class="comments-area"> </div> </article> </section> <aside id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm scrollspy"> <div id="sidebar"> <span><style type="text/css"></style><style type="text/css"></style><aside id="custom_html-9" class="widget_text widget widget_custom_html clearfix"><div class="textwidget custom-html-widget"><p>热门搜索: <a href="https://shluqu.cn/go/tengxun.html" target="_blank" rel="nofollow noopener">腾讯云</a> <a href="https://shluqu.cn/go/aliyun.html" target="_blank" rel="nofollow noopener">阿里云</a> <a href="https://shluqu.cn/go/?url=https://www.sugarhosts.com/members/aff.php?aff=3508" rel="nofollow noopener" target="_blank">SugarHosts</a> </p> <form data-min-no-for-search="1" data-result-box-max-height="400" data-form-id="5325" class="is-search-form is-form-style is-form-style-3 is-form-id-5325 is-ajax-search" action="https://shluqu.cn/" method="get" role="search" ><label for="is-search-input-5325"><span class="is-screen-reader-text">Search for:</span><input type="search" id="is-search-input-5325" name="s" value="" class="is-search-input" placeholder="输入主机商名称、关键词" autocomplete="off" /><span class="is-loader-image" style="display: none;background-image:url(https://shluqu.cn/wp-content/plugins/add-search-to-menu/public/images/spinner.gif);" ></span></label><button type="submit" class="is-search-submit"><span class="is-screen-reader-text">搜索按钮</span><span class="is-search-icon"><svg focusable="false" aria-label="Search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path></svg></span></button><input type="hidden" name="id" value="5325" /><input type="hidden" name="post_type" value="post" /></form> <br/> <form data-min-no-for-search="1" data-result-box-max-height="400" data-form-id="5324" class="is-search-form is-form-style is-form-style-3 is-form-id-5324 is-ajax-search" action="https://shluqu.cn/" method="get" role="search" ><label for="is-search-input-5324"><span class="is-screen-reader-text">Search for:</span><input type="search" id="is-search-input-5324" name="s" value="" class="is-search-input" placeholder="搜索全站文章" autocomplete="off" /><span class="is-loader-image" style="display: none;background-image:url(https://shluqu.cn/wp-content/plugins/add-search-to-menu/public/images/spinner.gif);" ></span></label><button type="submit" class="is-search-submit"><span class="is-screen-reader-text">搜索按钮</span><span class="is-search-icon"><svg focusable="false" aria-label="Search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path></svg></span></button><input type="hidden" name="id" value="5324" /><input type="hidden" name="post_type" value="post" /></form> </div></aside><aside id="custom_html-8" class="widget_text widget widget_custom_html clearfix"><div class="textwidget custom-html-widget"><div class="obs-heng-link"> <h3 class="obs-heng-a"><i class="fa fa-info-circle" aria-hidden="true"></i>热点解答</h3> </div> <h2 align="center"> 你需要了解…… </h2> <table style="width:100%;border: 1px solid #2220;" bordercolor="#000000" cellspacing="0" cellpadding="2" border="0"> <tbody> <tr> <td> <a href="https://shluqu.cn/tougao"> <p><i aria-hidden="true" class="fa fa-envelope fa-2x" style="color:#2a5cbf;"></i></p> <p>投稿给我们</p> </a> </td> <td> <a href="https://shluqu.cn/2816.html"> <p><i aria-hidden="true" class="fa fa-graduation-cap fa-2x" style="color:#2a5cbf;"></i></p> <p>如何建站?</p> </a> </td> </tr> <tr> <td> <a href="https://shluqu.cn/8368.html"> <p><i aria-hidden="true" class="fa fa-linux fa-2x" style="color:#2a5cbf;"></i></p> <p>vps是什么?</p> </a> </td> <td> <a href="https://shluqu.cn/16486.html"> <p><i aria-hidden="true" class="fa fa-television fa-2x" style="color:#2a5cbf;"></i></p> <p>如何安装宝塔?</p> </a> </td> </tr> <tr> <td> <a href="https://shluqu.cn/tag/bokezhuanqian"> <p><i aria-hidden="true" class="fa fa-usd fa-2x" style="color:#2a5cbf;"></i></p> <p>如何通过博客赚钱?</p> </a> </td> <td> <a href="https://shluqu.cn/16.html"> <p><i aria-hidden="true" class="fa fa-wordpress fa-2x" style="color:#2a5cbf;"></i></p> <p>便宜wordpress托管方案</p> </a> </td> </tr> <tr> <td> <a href="https://shluqu.cn/free-wordpress-themes"> <p><i aria-hidden="true" class="fa fa-wordpress fa-2x" style="color:#ec004a;"></i></p> <p>免费wordpress主题</p> </a> </td> <td> <a href="https://shluqu.cn/tag/free-plan"> <p><i aria-hidden="true" class="fa fa-database fa-2x" style="color:#2a5cbf;"></i></p> <p>这些都是免费方案</p> </a> </td> </tr> </tbody> </table></div></aside><aside id="shortcodes-ultimate-2" class="widget shortcodes-ultimate clearfix"><div class="obs-heng-link"> <h3 class="obs-heng-a"><i class="fa fa-cog" aria-hidden="true"></i>代理IP - 赞助商</h3></div><div class="textwidget"><a href="https://shluqu.cn/go/proxy-seller" target="_blank" rel="nofollow"><div align="center"><img src="https://shluqu-1252205774.file.myqcloud.com/wp-content/uploads/2025/07/20250703081311524.jpg" border=0></div></a> <br/> <a href="https://shluqu.cn/go/iproyal" target="_blank" rel="nofollow"><div align="center"><img src="https://shluqu-1252205774.file.myqcloud.com/wp-content/uploads/2025/07/20250703081313321.jpg" border=0></div></a><br/> <div class="su-list" style="margin-left:0px"> <ul> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>最强悍的住宅代理:<a href="https://brightproxies.com/" target="_blank" rel="nofollow noopener">Brightdata</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>4G代理的选择:<a href=" https://www.dailiproxy.com/proxy-seller.com" target="_blank" rel="nofollow noopener">Proxy-Seller</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>性价比的选择:<a href=" https://www.dailiproxy.com/smartproxy.com" target="_blank" rel="nofollow noopener">Smartproxy</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>静态住宅代理:<a href="https://www.dailiproxy.com/go/proxy-ipv4.com" target="_blank" rel="nofollow noopener">Proxy-IPV4</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>便宜的住宅代理:<a href=" https://www.dailiproxy.com/proxy-cheap.com" target="_blank" rel="nofollow noopener">Proxy-Cheap</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>无穷流量的选择:<a href=" https://www.dailiproxy.com/shifter.io" target="_blank" rel="nofollow noopener">Shifter</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>代理新手的选择:<a href="https://www.dailiproxy.com/go/iproyal.com" target="_blank" rel="nofollow noopener">IProyal</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>数据中心的选择:<a href=" https://www.dailiproxy.com/my-private-proxies" target="_blank" rel="nofollow noopener">Myprivateproxy</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>旋转数据代理:<a href="https://www.dailiproxy.com/webshare.io" target="_blank" rel="nofollow noopener">WebShare Proxy</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>社交账户代理:<a href="https://www.dailiproxy.com/go/proxy-sale.com" target="_blank" rel="nofollow noopener">Proxy-Sale</a></strong></li> <li><i class="sui sui-hand-o-right" style="color:#1512d3"></i> <strong>小众的住宅代理:<a href="https://www.dailiproxy.com/go/soax" target="_blank" rel="nofollow noopener">Soax</a></strong></li> </ul> </div> 赞助By:<a href=" https://www.dailiproxy.com" target="_blank" rel="nofollow noopener">Dailiproxy</a></div></aside><aside id="custom_html-7" class="widget_text widget widget_custom_html clearfix"><div class="obs-heng-link"> <h3 class="obs-heng-a"><i class="fa fa-cog" aria-hidden="true"></i>VPS 赞助商</h3></div><div class="textwidget custom-html-widget"><a href="http://www.west.cn/?ReferenceID=1901161" target="_blank" rel="nofollow noopener"><div align="center"><img src="https://shluqu-1252205774.file.myqcloud.com/wp-content/uploads/2022/03/20220330131043593.jpg" border=0></div></a> <br/> <p style="font-size: 14px;">豆丁博客专注国外VPS、国外服务器、国外虚拟主机、国外代理IP推荐,我们从用户使用体验出发,对国外VPS主机价格、速度、可靠性、客服等多个方面进行测评,为你推荐优秀的国外VPS/服务器/虚拟主机。同时我们还会分享最新的主机优惠码,让你花少的钱买到性价比较高的主机。</p> <a href="https://www.digitalocean.com/?refcode=3f858506cd39&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge"><div align="center"><img src="https://web-platforms.sfo2.cdn.digitaloceanspaces.com/WWW/Badge%201.svg" alt="DigitalOcean Referral Badge" /></div></a></div></aside> <aside id="recent-posts-2" class="widget widget_recent_entries clearfix"> <div class="obs-heng-link"> <h3 class="obs-heng-a"><i class="fa fa-cog" aria-hidden="true"></i>最近文章</h3></div> <ul> <li> <a href="https://shluqu.cn/34667.html">深入解析 Java Vector 的 add() 方法:从基础到实战进阶</a> </li> <li> <a href="https://shluqu.cn/34666.html">深入理解 SOAR:安全编排、自动化与响应的完全指南</a> </li> <li> <a href="https://shluqu.cn/34665.html">Tailwind CSS Justify Content 详解:精通弹性布局的主轴对齐</a> </li> <li> <a href="https://shluqu.cn/34664.html">Java 微服务面试全解析:面向 2026 的架构演进与实战指南</a> </li> <li> <a href="https://shluqu.cn/34663.html">深入理解 Java 反射机制:原理、实践与性能优化</a> </li> <li> <a href="https://shluqu.cn/34662.html">如何备份您的 Android 设备?</a> </li> <li> <a href="https://shluqu.cn/34661.html">电子元器件深度解析:2026年视角下的基石与前沿</a> </li> <li> <a href="https://shluqu.cn/34660.html">深入理解回溯法:如何高效生成数组的所有子集</a> </li> </ul> </aside> <aside id="kratos_tags-3" class="widget widget_kratos_tags clearfix"> <div id="recent-content"> <div class="obs-heng-link"> <h3 class="obs-heng-a"><i class="fa fa-book" aria-hidden="true"></i>相关专题</h3> </div> <div id="zazhi-2-home-block-one-5" class="widget-zazhi-2-home-block-one"> <div class="content-block content-block-1 clear"> </div> </div> </div> </aside> </span> </div> </aside> </div> </div> </div> <div class="navs"> <ul> <li> <a href="https://www.shluqu.cn/"><span class="font-text"><i class="fa-home fa"></i> 首页</span></a></li> <li> <a href="https://www.shluqu.cn/developer-tools"><span class="font-text"><i class="fa fa-pencil"></i>主机</span></a></li> <li> <a href="https://www.shluqu.cn/category/zhihudati"><span class="font-text"><i class="fa fa-at"></i>问答</span></a></li> <li> <a href="https://www.shluqu.cn/category/technology"><span class="font-text"><i class="fa fa-plus-square"></i> 技术</span></a></li> <li> <a href="https://www.shluqu.cn/category/make-money"><span class="font-text"><i class="fa fa-usd"></i> 赚钱</span></a></li> </ul> </div> <footer> <div id="footer"> <div class="cd-tool text-center"> <div class="gotop-box"><div class="gotop-btn"><span class="fa fa-chevron-up"></span></div></div> <div class="search-box"> <span class="fa fa-search"></span> <form class="search-form" role="search" method="get" id="searchform" action="https://shluqu.cn/"> <input type="text" name="s" id="search" placeholder="Search..." style="display:none"/> </form> </div> </div> <table width="80%" height="35" border="0" align="center" style="border: #2220;"> <tbody><tr> <td width="50%" style="color: #fff;"> <a class="Home11" href="https://www.shluqu.cn/4284.html">常见问题</a>  |  <a class="Home11" target="_blank" href="https://www.shluqu.cn/sitemap">网站地图</a>  |  <a class="Home11" href="https://about.shluqu.cn/">豆丁科技</a>  |  <a class="Home11" target="_blank" href="https://www.shluqu.cn/cloud-computing-keywords">关键词</a>  |  <a class="Home11" target="_blank" href="https://www.shluqu.cn/aliyun/">阿里云优惠</a> <br/> <a class="Home11" target="_blank" href="https://www.shluqu.cn/tougao">投稿</a>  |  <a class="Home11" href="https://www.shluqu.cn/guanyuwomen">关于我们</a>  |  <a class="Home11" href="https://www.shluqu.cn/zanzhushanghezuo">赞助商合作</a>  |  <a class="Home11" href="https://www.shluqu.cn/terms-of-service">服务条款</a>  |  <a class="Home11" href="https://www.shluqu.cn/privacy-policy">隐私政策</a> </td> <td width="50%" id="beian" class="has-text-centered is-size-7"> <a style="color: #f4f4f4;" target="_blank" rel="nofollow" href="http://beian.miit.gov.cn">鄂ICP备19029286号-4</a> <a style="color: #f4f4f4;" target="_blank" rel="nofollow" href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=42118102000305"><img src="https://shluqu-1252205774.file.myqcloud.com/wp-content/uploads/2021/11/20211102110945832.png" alt="公安备案">鄂公网安备 42118102000305号 </a><p style="color: #f4f4f4;">© 2002-2026 <a  href="https://www.shluqu.cn/">豆丁博客</a> Inc. All rights reserved.Powered by <a  href="https://www.shluqu.cn/">豆丁博客</a></p></td> </tr> </tbody></table> <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3 footer-list text-center"> <p class="kratos-social-icons"> </p> </div> </div> </div> </div> </footer> </div> </div> <style type="text/css" media="screen">.is-menu path.search-icon-path { fill: #ffffff;}body .popup-search-close:after, body .search-close:after { border-color: #ffffff;}body .popup-search-close:before, body .search-close:before { border-color: #ffffff;}</style><link rel='stylesheet' id='ivory-ajax-search-styles-css' href='https://shluqu.cn/wp-content/plugins/add-search-to-menu/public/css/ivory-ajax-search.min.css?ver=4.6.5' type='text/css' media='all' /> <link rel='stylesheet' id='su-icons-css' href='https://shluqu.cn/wp-content/plugins/shortcodes-ultimate/includes/css/icons.css?ver=1.1.5' type='text/css' media='all' /> <link rel='stylesheet' id='su-shortcodes-css' href='https://shluqu.cn/wp-content/plugins/shortcodes-ultimate/includes/css/shortcodes.css?ver=5.10.2' type='text/css' media='all' /> <script type='text/javascript' src='https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill.min.js?ver=7.4.4' id='wp-polyfill-js'></script> <script type='text/javascript' id='wp-polyfill-js-after'> ( 'fetch' in window ) || document.write( '<script src="https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js?ver=3.0.0"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src="https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill-node-contains.min.js?ver=3.42.0"></scr' + 'ipt>' );( window.DOMRect ) || document.write( '<script src="https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill-dom-rect.min.js?ver=3.42.0"></scr' + 'ipt>' );( window.URL && window.URL.prototype && window.URLSearchParams ) || document.write( '<script src="https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill-url.min.js?ver=3.6.4"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src="https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill-formdata.min.js?ver=3.0.12"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src="https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js?ver=2.0.2"></scr' + 'ipt>' );( 'objectFit' in document.documentElement.style ) || document.write( '<script src="https://shluqu.cn/wp-includes/js/dist/vendor/wp-polyfill-object-fit.min.js?ver=2.3.4"></scr' + 'ipt>' ); </script> <script type='text/javascript' id='contact-form-7-js-extra'> /* <![CDATA[ */ var wpcf7 = {"api":{"root":"https:\/\/shluqu.cn\/wp-json\/","namespace":"contact-form-7\/v1"},"cached":"1"}; /* ]]> */ </script> <script type='text/javascript' src='https://shluqu.cn/wp-content/plugins/contact-form-7/includes/js/index.js?ver=5.4.2' id='contact-form-7-js'></script> <script type='text/javascript' id='toc-front-js-extra'> /* <![CDATA[ */ var tocplus = {"visibility_show":"\u663e\u793a","visibility_hide":"\u9690\u85cf","width":"33%"}; /* ]]> */ </script> <script type='text/javascript' src='http://shluqu.cn/wp-content/plugins/table-of-contents-plus/front.min.js?ver=2106' id='toc-front-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/jquery.easing.min.js?ver=1.3.0' id='easing-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/jquery.qrcode.min.js?ver=2.8' id='qrcode-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/layer.min.js?ver=3.0.3' id='layer-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/bootstrap.min.js?ver=3.3.7' id='bootstrap-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/jquery.waypoints.min.js?ver=4.0.0' id='waypoints-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/jquery.stellar.min.js?ver=0.6.2' id='stellar-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/hoverIntent.min.js?ver=r7' id='hoverIntents-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/superfish.js?ver=1.0.0' id='superfish-js'></script> <script type='text/javascript' id='kratos-js-extra'> /* <![CDATA[ */ var kratos = {"site":"https:\/\/shluqu.cn"}; /* ]]> */ </script> <script type='text/javascript' src='https://shluqu.cn/wp-content/themes/shluqu/js/kratos.js?ver=2.8' id='kratos-js'></script> <script type='text/javascript' id='post-ratings-js-extra'> /* <![CDATA[ */ var post_ratings = {"ajaxURL":"https:\/\/shluqu.cn\/wp-admin\/admin-ajax.php","nonce":"4cd7a16127","path":"http:\/\/shluqu.cn\/wp-content\/plugins\/post-ratings\/assets\/images\/","number":"5"}; /* ]]> */ </script> <script type='text/javascript' src='http://shluqu.cn/wp-content/plugins/post-ratings/js/post-ratings.js?ver=3.0' id='post-ratings-js'></script> <script type='text/javascript' src='http://shluqu.cn/wp-content/plugins/post-ratings/assets/jquery.raty.js?ver=3.0' id='post-ratings-raty-js'></script> <script type='text/javascript' id='ivory-search-scripts-js-extra'> /* <![CDATA[ */ var IvorySearchVars = {"is_analytics_enabled":"1"}; /* ]]> */ </script> <script type='text/javascript' src='https://shluqu.cn/wp-content/plugins/add-search-to-menu/public/js/ivory-search.min.js?ver=4.6.5' id='ivory-search-scripts-js'></script> <script type='text/javascript' src='https://shluqu.cn/wp-includes/js/wp-embed.min.js?ver=5.7.2' id='wp-embed-js'></script> <script type='text/javascript' id='ivory-ajax-search-scripts-js-extra'> /* <![CDATA[ */ var IvoryAjaxVars = {"ajaxurl":"https:\/\/shluqu.cn\/wp-admin\/admin-ajax.php","ajax_nonce":"9302e0b3f0"}; /* ]]> */ </script> <script type='text/javascript' src='https://shluqu.cn/wp-content/plugins/add-search-to-menu/public/js/ivory-ajax-search.min.js?ver=4.6.5' id='ivory-ajax-search-scripts-js'></script> </body> </html> <!-- This website is like a Rocket, isn't it? Performance optimized by WP Rocket. Learn more: https://wp-rocket.me --><script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>