当前位置: 首页 > article >正文

Vue的实例

Every Vue application starts with a single Vue component instance as the application root. Any other Vue component created in the same application needs to be nested inside this root component.

每个 Vue 应用都以一个 Vue 组件实例作为应用的根开始。在同一个应用中创建的任何其他 Vue 组件都需要嵌套在这个根组件内部。

In Vue 2, Vue exposes a Vue class (or JavaScript function) for you to create a Vue component instance based on a set of configuration options, using the following syntax:

在 Vue 2 中,Vue 暴露了一个 Vue 类(或 JavaScript 函数),你可以基于一组配置选项使用以下语法创建一个 Vue 组件实例:

const App = {
  //component's options
}
const app = new Vue(App)

Vue receives a component, or the component’s configuration to be more precise. A component’s configuration is an Object containing all the component’s initial configuration options. We call the structure of this argument Options API, which is another of Vue’s core APIs.

Vue 接收一个组件,或者更准确地说,是接收一个组件的配置。组件的配置是一个 Object,包含组件的所有初始配置选项。我们称这个参数的结构为 Options API,这是 Vue 的另一个核心 API。

Beginning with Vue 3, you can no longer call new Vue() directly. Instead, you create the application instance using the createApp() method from the vue package. This change in functionality enhances the isolation of each Vue instance created both on dependencies and shared components (if any) and the code readability:

从 Vue 3 开始,你不能再直接调用 new Vue()。相反,你需要使用 vue 包中的 createApp() 方法来创建应用实例。这一功能的改变增强了每个 Vue 实例在依赖和共享组件(如果有)方面的隔离性,并提高了代码的可读性:

import { createApp } from 'vue'

const App = {
  //component's options
}

const app = createApp(App)

createApp() also accepts an Object of the component’s configurations. Based on these configurations, Vue creates a Vue component instance as its application root app. Then you need to mount the root component app to the desired HTML element using the app.mount() method, as follows:

createApp() 同样接受一个包含组件配置的 Object。根据这些配置,Vue 会创建一个以应用根 app 为形式的 Vue 组件实例。然后,你需要使用 app.mount() 方法将根组件 app 挂载到指定的 HTML 元素上,如下所示:

app.mount('#app')

#app is the unique id selector for the application’s root element. The Vue engine queries for the element using this id, mounts the app instance to it, then renders the application in the browser.

#app 是应用程序根元素的唯一 id 选择器。Vue 引擎使用这个 id 查找元素,将应用实例挂载到该元素上,然后在浏览器中渲染应用程序。


http://www.kler.cn/a/611517.html

相关文章:

  • Three.js 快速入门教程【十八】射线拾取模型——鼠标点击屏幕选中模型或物体
  • 【AI大模型】搭建本地大模型GPT-J:详细步骤及常见问题
  • 计算机视觉中的椭圆带权平均算法全解析
  • 【NLP 44、实践 ⑪ 用Bert模型结构实现自回归语言模型的训练】
  • Docker技术系列文章,第七篇——Docker 在 CI/CD 中的应用
  • 全息教学系统的软件开发,沉浸式数字沙盘展示系统如何改变历史教学
  • 孟德尔随机化:脑卒中研究新钥匙
  • Linux 设备分类详解:字符设备、块设备与网络设备解析
  • Java后端API限流秘籍:高并发的防护伞与实战指南
  • MySQL 5.7升级8.0报异常:ONLY_FULL_GROUP_BY
  • 飞速(FS)InfiniBand解决方案助力领先科技公司网络升级
  • playwright-go实战:自动化登录测试
  • 华为Pura先锋盛典及鸿蒙智家产品发布,空气算法重构健康家居“阔”美学
  • Linux的一些常见指令
  • 探索PyMOL新插件NRGSuite-Qt:全面提升分子对接、结合位点预测与动力学模拟的研究效率
  • 低空智能目标(无人机)管理控制系统技术详解
  • 进军场景智能体,云迹机器人又快了一步
  • 【C++网络编程】第8篇:协议设计与序列化(Protobuf、FlatBuffers)
  • Containerd+Kubernetes搭建k8s集群
  • Svelte 深度理解