Skip to content

Commit 3926008

Browse files
committed
instance methods
1 parent c006bbc commit 3926008

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

source/api/instance-methods.md

+46-6
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,51 @@ Set a data value on the Vue instance given a valid keypath. If the path doesn't
6060

6161
### vm.$add( keypath, value )
6262

63+
- **keypath** `String`
64+
- **value** `*`
65+
66+
Add a root level property to the Vue instance (and also its `$data`). Due to the limitations of ES5, Vue cannot detect properties directly added to or deleted from an Object, so use this method and `vm.$delete` when you need to do so. Additionally, all observed objects are augmented with these two methods too.
67+
6368
### vm.$delete( keypath )
6469

65-
### vm.$eval( directiveText )
70+
- **keypath** `String`
71+
72+
Delete a root level property on the Vue instance (and also its `$data`).
73+
74+
### vm.$eval( expression )
75+
76+
- **expression** `String`
77+
78+
Evaluate an expression that can also contain filters.
79+
80+
``` js
81+
// assuming vm.msg = 'hello'
82+
vm.$eval('msg | uppercase') // -> 'HELLO'
83+
```
6684

6785
### vm.$interpolate( templateString )
6886

87+
- **templateString** `String`
88+
89+
Evaluate a piece of template string containing mustache interpolations. Note that this method simply performs string interpolation; attribute directives are not compiled.
90+
91+
``` js
92+
// assuming vm.msg = 'hello'
93+
vm.$interpolate('{{msg}} world!') // -> 'hello world!'
94+
```
95+
6996
### vm.$log( [keypath] )
7097

71-
## Cross-ViewModel Events
98+
- **keypath** `String` *optional*
99+
100+
Log the current instance data as a plain object, which is more console-inspectable than a bunch of getter/setters. Also accepts an optional key.
101+
102+
``` js
103+
vm.$log() // logs entire ViewModel data
104+
vm.$log('item') // logs vm.item
105+
```
106+
107+
## Events
72108

73109
> Each vm is also an event emitter. When you have multiple nested ViewModels, you can use the event system to communicate between them.
74110
@@ -77,14 +113,14 @@ Set a data value on the Vue instance given a valid keypath. If the path doesn't
77113
- **event** `String`
78114
- **args...** *optional*
79115

80-
Dispatch an event from the current vm that propagates all the way up to its `$root`.
116+
Dispatch an event from the current vm that propagates all the way up to its `$root`. If a callback returns `false`, it will stop the propagation at its owner instance.
81117

82118
### vm.$broadcast( event, [args...] )
83119

84120
- **event** `String`
85121
- **args...** *optional*
86122

87-
Emit an event to all children vms of the current vm, which gets further broadcasted to their children all the way down.
123+
Emit an event to all children vms of the current vm, which gets further broadcasted to their children all the way down. If a callback returns `false`, its owner instance will not broadcast the event any further.
88124

89125
### vm.$emit( event, [args...] )
90126

@@ -114,7 +150,7 @@ Attach a one-time only listener for an event.
114150

115151
If no arguments are given, stop listening for all events; if only the event is given, remove all callbacks for that event; if both event and callback are given, remove that specific callback only.
116152

117-
## DOM Manipulation
153+
## DOM
118154

119155
> All vm DOM manipulation methods work like their jQuery counterparts - except they also trigger Vue.js transitions if there are any declared on vm's `$el`. For more details on transitions see [Adding Transition Effects](/guide/transitions.html).
120156
@@ -151,6 +187,8 @@ Remove the vm's `$el` from the DOM.
151187

152188
- **element** `HTMLElement` | **selector** `String` *optional*
153189

190+
If the Vue instance didn't get an `el` option at instantiation, you can manually call `$mount()` to assign an element to it and start the compilation. If no argument is provided, an empty `<div>` will be automatically created. Calling `$mount()` on an already mounted instance will have no effect. The method returns the instance itself so you can chain other instance methods after it.
191+
154192
### vm.$destroy( [remove] )
155193

156194
- **remove** `Boolean` *optional*
@@ -159,4 +197,6 @@ Completely destroy a vm. Clean up its connections with other existing vms, unbin
159197

160198
### vm.$compile( element )
161199

162-
- **element** `HTMLElement`
200+
- **element** `HTMLElement`
201+
202+
Partially compile a piece of DOM (Element or DocumentFragment). The method returns a `decompile` function that tearsdown the directives created during the process. Note the decompile function does not remove the DOM. This method is exposed primarily for writing advanced custom directives.

source/api/options.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type: api
33
order: 2
44
---
55

6-
## Data & Logic
6+
## Data
77

88
### data
99

@@ -139,7 +139,7 @@ There are some special cases when using `paramAttributes` with attributes that c
139139

140140
This means a param attribute `data-hello` will be set on the vm as `vm.hello`; And `my-param` will be set as `vm.myParam`.
141141

142-
## DOM Element
142+
## DOM
143143

144144
### el
145145

@@ -170,7 +170,7 @@ If it starts with `#` it will be used as a querySelector and use the selected el
170170

171171
Whether to replace the original `vm.$el` with the template's content instead of appending to it.
172172

173-
## Lifecycle Hooks
173+
## Lifecycle
174174

175175
All lifecycle hooks have their `this` context bound to the Vue instance they belong to. The Vue instance will also fire corresponding events for each hook in the form of `"hook:<hookName>"`. e.g. for `created`, a `"hook:created"` event will be fired.
176176

@@ -196,7 +196,7 @@ Called after the compilation is finished. At this stage all directives have been
196196

197197
- **Type:** `Function`
198198

199-
Called after compilation **and** the `$el` is inserted into the document for the first time.
199+
Called after compilation **and** the `$el` is **inserted into the document for the first time**. Note this insertion must be executed via Vue (with methods like `vm.$appendTo()` or as a result of a directive update) to trigger the `ready` hook.
200200

201201
### attached
202202

source/guide/components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var MyComponent = Vue.extend({
7474
})
7575
```
7676

77-
Check out the API reference for a [full list of lifecycle hooks](/api/options.html#Lifecycle_Hooks) that are availble.
77+
Check out the API reference for a [full list of lifecycle hooks](/api/options.html#Lifecycle) that are availble.
7878

7979
## Data Inheritance
8080

@@ -272,7 +272,7 @@ When `v-ref` is used together with `v-repeat`, the value you get will be an Arra
272272

273273
## Event System
274274

275-
Although you can directly access a ViewModels children and parent, it is more convenient to use the built-in event system for cross-component communication. It also makes your code less coupled and easier to maintain. Once a parent-child relationship is established, you can dispatch and trigger events using each ViewModel's [event instance methods](/api/instance-methods.html#Cross-ViewModel_Events).
275+
Although you can directly access a ViewModels children and parent, it is more convenient to use the built-in event system for cross-component communication. It also makes your code less coupled and easier to maintain. Once a parent-child relationship is established, you can dispatch and trigger events using each ViewModel's [event instance methods](/api/instance-methods.html#Events).
276276

277277
``` js
278278
var Child = Vue.extend({

source/guide/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ You can use triple mustaches for unescaped HTML, which translates to `v-html` in
8989

9090
However, this can open up windows for potential XSS attacks, therefore it is suggested that you only use triple mustaches when you are absolutely sure about the security of the data source, or pipe it through a custom filter that sanitizes untrusted HTML.
9191

92+
Finally, you can add `*` to your mustache bindings to indicate a one-time only interpolation, which does not react to data changes:
93+
94+
``` html
95+
{&#123;* onlyOnce &#125;}
96+
```
97+
9298
### Filters
9399

94100
Filters are functions used to process the raw values before updating the View. They are denoted by a "pipe" inside directives or bindings:

0 commit comments

Comments
 (0)