Week 2 Post-class 1.2: Test your Knowledge
这一页有部分内容暂时无法显示,其余内容完整。
Question 1
Which of the following statements accurately describes the use of JSON in web development?
- JSON is a binary format used for efficient data storage.
- JSON is primarily used for data transfer between a server and a web application.
- JSON is a markup language similar to HTML
- JSON requires special parsing libraries in all programming languages.
以下哪项陈述准确描述了 JSON 在 Web 开发中的用途?
此处有一段内容暂不支持显示。
- 1 错误:JSON 是纯文本格式(text-based),而不是二进制格式。
- 2 正确:JSON 最常用于服务器与客户端之间的数据交换。
- 3 错误:JSON 不是标记语言,而是数据表示格式,与 HTML 有本质区别。
- 4 错误:大多数现代编程语言(如 JavaScript、Python)都内置或轻松支持 JSON 解析,不需要特殊库。
Question 2
Why might a developer choose JSON over XML for data interchange?
- JSON supports a wider range of data types than XML.
- JSON provides better support for multimedia content.
- JSON can represent complex documents more efficiently than XML.
- JSON is easier to parse and generally more lightweight compared to XML.
为什么开发者在数据交换时会选择 JSON 而不是 XML?
此处有一段内容暂不支持显示。
- 1 错误:XML 实际上支持的数据类型比 JSON 更丰富,尤其在定义结构上更灵活。
- 2 错误:多媒体通常不通过 JSON 或 XML 直接传输,二者都不是为多媒体内容设计的。
- 3 错误:虽然 JSON 简洁,但在表达非常复杂、嵌套层级深的文档时不一定比 XML 更高效。
- 4 正确:JSON 语法更简洁,易读易写,且无需复杂解析器,适合轻量级数据交换场景。
Question 3
Which of the following scenarios is an inappropriate use case for Vue.js computed properties?
- To compute values that depend on reactive data.
- To perform heavy computations on demand.
- To update a value that involves side effects like making an API call.
- To concatenate strings derived from data properties.
以下哪种情况是不适合使用 Vue.js 中的计算属性(computed)的?
此处有一段内容暂不支持显示。
- 1 正确用法:计算属性的主要目的就是依赖响应式数据进行自动更新。
- 2 适用:虽然不推荐将非常耗时的逻辑放在 computed 中,但中等复杂度的计算依然适合。
- 3 错误用法(正确选项):computed 不应包含副作用操作,比如 API 调用,这种情况应使用
watch或methods。 - 4 正确用法:字符串拼接是计算属性中常见的轻量逻辑,非常适合用 computed 来处理。
Question 4
When using the v-bind directive for attribute binding in Vue.js, which of the following is a correct syntax to dynamically set the href attribute of an anchor tag to a data property url?
- <a v-bind:href="'url'"></a>
- <a :href="'url'"></a>
<a v-bind:href="url"></a>- <a href="{{ url }}"></a>
在 Vue.js 中使用 v-bind 指令进行属性绑定时,以下哪种语法是将锚标签(<a>)的 href 属性动态绑定到数据属性 url 的正确方式?
此处有一段内容暂不支持显示。
- 1 错误:引号中的
'url'是字符串字面量,不会绑定到变量。 - 2 错误:同样是绑定成了字符串
'url',不是变量。 - 3 正确:Vue 中
v-bind:href="url"(或简写为:href="url")表示将href动态绑定到变量url。 - 4 错误:
{{ url }}是插值语法,只适用于内容渲染,而不能用于绑定 HTML 属性。
Question 5
What is a key difference between v-if and v-show directives in Vue.js?
v-ifis used for CSS whilev-showis for JS items.v-ifconditionally renders elements, whereasv-showtoggles the visibility of elements using CSS.v-showconditionally renders elements, whilev-ifis used to bind attributes- Both
v-ifandv-showremove elements from the DOM but use different syntax.
在 Vue.js 中,v-if 和 v-show 指令的主要区别是什么?
此处有一段内容暂不支持显示。
- 1 错误:这两个指令都不是用于分类 JS 或 CSS 项目的。
- 2 正确:
v-if完全移除或插入 DOM 元素,而v-show只是切换元素的display样式属性。 - 3 错误:两者都与属性绑定无关,
v-if是用于控制 DOM 渲染的条件。 - 4 错误:只有
v-if会移除元素,v-show只是隐藏它,DOM 元素依然存在。