Skip to content

Commit b3342d8

Browse files
committed
commit api 4 and 5
1 parent 26bb4b6 commit b3342d8

File tree

1 file changed

+75
-75
lines changed

1 file changed

+75
-75
lines changed

src/api/index.md

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -518,182 +518,182 @@ type: api
518518

519519
- **See also:** [Instance Methods - vm.$watch](#vm-watch)
520520

521-
## Options / DOM
521+
## 选项 / DOM
522522

523523
### el
524524

525-
- **Type:** `string | HTMLElement`
525+
- **类型:** `string | HTMLElement`
526526

527-
- **Restriction:** only respected in instance creation via `new`.
527+
- **限制:** 只在由 `new` 创建的实例中遵守。
528528

529-
- **Details:**
529+
- **详细:**
530530

531-
Provide the Vue instance an existing DOM element to mount on. It can be a CSS selector string or an actual HTMLElement.
531+
为实例提供挂载元素。值可以是 CSS 选择符,或实际 HTML 元素。
532532

533-
After the instance is mounted, the resolved element will be accessible as `vm.$el`.
533+
在实例挂载之后, 元素可以用 `vm.$el` 访问。
534534

535-
If this option is available at instantiation, the instance will immediately enter compilation; otherwise, the user will have to explicitly call `vm.$mount()` to manually start the compilation.
535+
如果在初始化的时候指定了该选项,实例将立即进入编译过程,否则,需要显式调用 `vm.$mount()` 手动开启编译。
536536

537-
<p class="tip">The provided element merely serves as a mounting point. Unlike in Vue 1.x, the mounted element will be replaced with Vue-generated DOM in all cases. It is therefore not recommended to mount the root instance to `<html>` or `<body>`.</p>
537+
<p class="tip"> 提供的元素只能作为挂载点。不同于 Vue 1.x,所有的挂载元素会被 Vue 生成的 DOM 替换。因此不推荐挂载root实例到 `<html>` 或者 `<body>` 上。</p>
538538

539-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
539+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
540540

541541
### template
542542

543-
- **Type:** `string`
543+
- **类型:** `string`
544544

545-
- **Details:**
545+
- **详细:**
546546

547-
A string template to be used as the markup for the Vue instance. The template will **replace** the mounted element. Any existing markup inside the mounted element will be ignored, unless content distribution slots are present in the template.
547+
一个字符串模板作为 Vue 实例的标识使用。模板将会 **替换** 挂载元素。挂载元素的内容都将被忽略,除非模板有内容分发 slot。
548548

549-
If the string starts with `#` it will be used as a querySelector and use the selected element's innerHTML as the template string. This allows the use of the common `<script type="x-template">` trick to include templates.
549+
如果值以 `#` 开始,则它用作选项符,将使用匹配元素的 innerHTML 作为模板。常用的技巧是用 `<script type="x-template">` 包含模板。
550550

551-
<p class="tip">From a security perspective, you should only use Vue templates that you can trust. Never use user-generated content as your template.</p>
551+
<p class="tip">出于安全考虑,你应该只使用你信任的 Vue 模板。避免使用其他用户级的代码作为你的模板。</p>
552552

553-
- **See also:**
554-
- [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
555-
- [Content Distribution](/guide/components.html#Content-Distribution-with-Slots)
553+
- **另见:**
554+
- [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
555+
- [内容分发](/guide/components.html#Content-Distribution-with-Slots)
556556

557557
### render
558558

559-
- **Type:** `Function`
559+
- **类型:** `Function`
560560

561-
- **Details:**
561+
- **详细:**
562562

563-
An alternative to string templates allowing you to leverage the full programmatic power of JavaScript. The render function receives a `createElement` method as it's first argument used to create `VNode`s.
563+
一个可替换的字符串模板允许你发挥 JavaScript 最大的编程能力。render 函数接收一个 `createElement` 方法作为第一个参数用来创建 `VNode`
564564

565-
If the component is a functional component, the render function also receives an extra argument `context`, which provides access to contextual data since functional components are instance-less.
565+
如果组件是一个函数组件,Render 函数还会接收一个额外的 `context` 参数,为没有实例的函数组件提供上下文信息。
566566

567-
- **See also:**
568-
- [Render Functions](/guide/render-function)
567+
- **另见:**
568+
- [Render 函数](/guide/render-function)
569569

570-
## Options / Lifecycle Hooks
570+
## 选项 / 生命周期钩子
571571

572-
All lifecycle hooks automatically have their `this` context bound to the instance, so that you can access data, computed properties, and methods. This means __you should not use an arrow function to define a lifecycle method__ (e.g. `created: () => this.fetchTodos()`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.fetchTodos` will be undefined.
572+
所有的生命周期钩子自动绑定 `this` 上下文到实例中,因此你可以访问数据,对属性和方法进行运算。这意味着 __你不能使用箭头函数来定义一个生命周期方法__ (例如 `created: () => this.fetchTodos()`)。这是因为箭头函数绑定了父上下文,因此 `this` 与你期待的 Vue 实例不同, `this.fetchTodos` 的行为未定义。
573573

574574
### beforeCreate
575575

576-
- **Type:** `Function`
576+
- **类型:** `Function`
577577

578-
- **Details:**
578+
- **详细:**
579579

580-
Called synchronously after the instance has just been initialized, before data observation and event/watcher setup.
580+
发生在实例初始化之后,数据观测(data observer) 和 event/watcher 事件配置之前。
581581

582-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
582+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
583583

584584
### created
585585

586-
- **Type:** `Function`
586+
- **类型:** `Function`
587587

588-
- **Details:**
588+
- **详细:**
589589

590-
Called synchronously after the instance is created. At this stage, the instance has finished processing the options which means the following have been set up: data observation, computed properties, methods, watch/event callbacks. However, the mounting phase has not been started, and the `$el` property will not be available yet.
590+
发生在实例已经创建完成之后。在这一步,实例已完成以下的配置:数据观测(data observer),属性和方法的运算, watch/event 事件回调。然而,挂载阶段还没开始,`$el` 属性目前不可见。
591591

592-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
592+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
593593

594594
### beforeMount
595595

596-
- **Type:** `Function`
596+
- **类型:** `Function`
597597

598-
- **Details:**
598+
- **详细:**
599599

600-
Called right before the mounting begins: the `render` function is about to be called for the first time.
600+
在挂载开始之前被调用:相关的 `render` 函数首次被调用。
601601

602-
**This hook is not called during server-side rendering.**
602+
**该钩子在服务器端渲染期间不被调用。**
603603

604-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
604+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
605605

606606
### mounted
607607

608-
- **Type:** `Function`
608+
- **类型:** `Function`
609609

610-
- **Details:**
610+
- **详细:**
611611

612-
Called after the instance has just been mounted where `el` is replaced by the newly created `vm.$el`. If the root instance is mounted to an in-document element, `vm.$el` will also be in-document when `mounted` is called.
612+
`el` 被新创建的 `vm.$el` 替换,并挂载到实例上去之后调用该钩子。如果 root 实例挂载了一个文档内元素,当 `mounted` 被调用时 `vm.$el` 也在文档内。
613613

614-
**This hook is not called during server-side rendering.**
614+
**该钩子在服务器端渲染期间不被调用。**
615615

616-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
616+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
617617

618618
### beforeUpdate
619619

620-
- **Type:** `Function`
620+
- **类型:** `Function`
621621

622-
- **Details:**
622+
- **详细:**
623623

624-
Called when the data changes, before the virtual DOM is re-rendered and patched.
624+
数据更新时调用,发生在虚拟 DOM 重新渲染和打补丁之前。
625625

626-
You can perform further state changes in this hook and they will not trigger additional re-renders.
626+
你可以在这个钩子中进一步地更改状态,这不会触发附加的重渲染过程。
627627

628-
**This hook is not called during server-side rendering.**
628+
**该钩子在服务器端渲染期间不被调用。**
629629

630-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
630+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
631631

632632
### updated
633633

634-
- **Type:** `Function`
634+
- **类型:** `Function`
635635

636-
- **Details:**
636+
- **详细:**
637637

638-
Called after a data change causes the virtual DOM to be re-rendered and patched.
638+
由于数据更改导致的虚拟 DOM 重新渲染和打补丁,在这之后会调用该钩子。
639639

640-
The component's DOM will be in updated state when this hook is called, so you can perform DOM-dependent operations in this hook. However, in most cases you should avoid changing state in this hook, because it may lead to an infinite update loop.
640+
当这个钩子被调用时,组件 DOM 已经更新,所以你现在可以执行依赖于 DOM 的操作。然而在大多数情况下,你应该避免在此期间更改状态,因为这可能会导致更新无限循环。
641641

642-
**This hook is not called during server-side rendering.**
642+
**该钩子在服务器端渲染期间不被调用。**
643643

644-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
644+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
645645

646646
### activated
647647

648-
- **Type:** `Function`
648+
- **类型:** `Function`
649649

650-
- **Details:**
650+
- **详细:**
651651

652-
Called when a kept-alive component is activated.
652+
keep-alive 组件激活时调用。
653653

654-
**This hook is not called during server-side rendering.**
654+
**该钩子在服务器端渲染期间不被调用。**
655655

656-
- **See also:**
656+
- **另见:**
657657
- [Built-in Components - keep-alive](#keep-alive)
658658
- [Dynamic Components - keep-alive](/guide/components.html#keep-alive)
659659

660660
### deactivated
661661

662-
- **Type:** `Function`
662+
- **类型:** `Function`
663663

664-
- **Details:**
664+
- **详细:**
665665

666-
Called when a kept-alive component is deactivated.
666+
keep-alive 组件停用时调用。
667667

668-
**This hook is not called during server-side rendering.**
668+
**该钩子在服务器端渲染期间不被调用。**
669669

670-
- **See also:**
670+
- **另见:**
671671
- [Built-in Components - keep-alive](#keep-alive)
672672
- [Dynamic Components - keep-alive](/guide/components.html#keep-alive)
673673

674674
### beforeDestroy
675675

676-
- **Type:** `Function`
676+
- **类型:** `Function`
677677

678-
- **Details:**
678+
- **详细:**
679679

680-
Called right before a Vue instance is destroyed. At this stage the instance is still fully functional.
680+
实例销毁之前调用。在这一步,实例仍然完全可用。
681681

682-
**This hook is not called during server-side rendering.**
682+
**该钩子在服务器端渲染期间不被调用。**
683683

684-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
684+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
685685

686686
### destroyed
687687

688-
- **Type:** `Function`
688+
- **类型:** `Function`
689689

690-
- **Details:**
690+
- **详细:**
691691

692-
Called after a Vue instance has been destroyed. When this hook is called, all directives of the Vue instance have been unbound, all event listeners have been removed, and all child Vue instances have also been destroyed.
692+
Vue 实例销毁后调用。调用后,Vue 实例指示的所有东西都会解绑定,所有的事件监听器会被移除,所有的子实例也会被销毁。
693693

694-
**This hook is not called during server-side rendering.**
694+
**该钩子在服务器端渲染期间不被调用。**
695695

696-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
696+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
697697

698698
## Options / Assets
699699

0 commit comments

Comments
 (0)