You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/v2/cookbook/adding-instance-properties.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -22,19 +22,19 @@ new Vue({
22
22
})
23
23
```
24
24
25
-
Then `"My App"` will be logged to the console. It's that simple!
25
+
Then `"My App"` will be logged to the console!
26
26
27
27
## The Importance of Scoping Instance Properties
28
28
29
29
You may be wondering:
30
30
31
31
> "Why does `appName` start with `$`? Is that important? What does it do?
32
32
33
-
No magic is happening here. `$` is simply a convention Vue uses for properties that are available to all instances. This avoids conflicts with any defined data, computed properties, or methods.
33
+
No magic is happening here. `$` is a convention Vue uses for properties that are available to all instances. This avoids conflicts with any defined data, computed properties, or methods.
34
34
35
35
> "Conflicts? What do you mean?"
36
36
37
-
Another great question! If you just set:
37
+
Another great question! If you set:
38
38
39
39
```js
40
40
Vue.prototype.appName='My App'
@@ -46,7 +46,7 @@ Then what would you expect to be logged below?
46
46
newVue({
47
47
data: {
48
48
// Uh oh - appName is *also* the name of the
49
-
// instance property we just defined!
49
+
// instance property we defined!
50
50
appName:'The name of some other app'
51
51
},
52
52
beforeCreate:function () {
@@ -143,7 +143,7 @@ As long as you're vigilant in scoping prototype properties, using this pattern i
143
143
144
144
However, it can sometimes cause confusion with other developers. They might see `this.$http`, for example, and think, "Oh, I didn't know about this Vue feature!" Then they move to a different project and are confused when `this.$http` is undefined. Or, maybe they want to Google how to do something, but can't find results because they don't realize they're actually using Axios under an alias.
145
145
146
-
__The convenience comes at the cost of explicitness.__ When just looking at a component, it's impossible to tell where `$http` came from. Vue itself? A plugin? A coworker?
146
+
__The convenience comes at the cost of explicitness.__ When looking at a component, it's impossible to tell where `$http` came from. Vue itself? A plugin? A coworker?
147
147
148
148
So what are the alternatives?
149
149
@@ -171,7 +171,7 @@ var App = Object.freeze({
171
171
172
172
<pclass="tip">If you raised an eyebrow at `Object.freeze`, what it does is prevent the object from being changed in the future. This essentially makes all its properties constants, protecting you from future state bugs.</p>
173
173
174
-
Now the source of these shared properties is much more obvious: there's an `App` object defined somewhere in the app. To find it, developers need only run a project-wide search.
174
+
Now the source of these shared properties is more obvious: there's an `App` object defined somewhere in the app. To find it, developers can run a project-wide search.
175
175
176
176
Another advantage is that `App` can now be used _anywhere_ in your code, whether it's Vue-related or not. That includes attaching values directly to instance options, rather than having to enter a function to access properties on `this`:
177
177
@@ -188,6 +188,6 @@ new Vue({
188
188
189
189
### When Using a Module System
190
190
191
-
When you have access to a module system, you can easily organize shared code into modules, then `require`/`import` those modules wherever they're needed. This is the epitome of explicitness, because in each file you gain a list of dependencies. You know _exactly_ each one came from.
191
+
When you have access to a module system, you can easily organize shared code into modules, then `require`/`import` those modules wherever they're needed. This is the epitome of explicitness, because in each file you gain a list of dependencies. You know _exactly_where each one came from.
192
192
193
193
While certainly more verbose, this approach is definitely the most maintainable, especially when working with other developers and/or building a large app.
<pclass="tip">This cookbook is still in its very early stages. At this point, we will not be linking to it from anywhere else. Pages may be removed or reorganized at any time. Even the goals and overall format are still in flux.</p>
How is the cookbook different from the guide? Why is this necessary?
13
+
这份 cookbook 和指南的不同之处在哪里?存在的意义是什么?
14
14
15
-
***Greater Focus**: In the guide, we're essentially telling a story. Each section builds on and assumes knowledge from each previous section. In the cookbook, each recipe can and should stand on its own. This means recipes can focus on one specific aspect of Vue, rather than having to give a general overview.
***Greater Depth**: To avoid making the guide too long, we try to include only the simplest possible examples to help you understand each feature. Then we move on. In the cookbook, we can include more complex examples, combining features in interesting ways. Each recipe can also be as long and detailed as it needs to be, in order to fully explore its niche.
***Teaching JavaScript**: In the guide, we assume at least intermediate familiarity with ES5 JavaScript. For example, we won't explain how `Array.prototype.filter`works in a computed property that filters a list. In the cookbook however, essential JavaScript features (including ES6/2015+) can be explored and explained in the context of how they help us build better Vue applications.
***Exploring the Ecosystem**: For advanced features, we assume some ecosystem knowledge. For example, if you want to use single-file components in Webpack, we don't explain how to configure the non-Vue parts of the Webpack config. In the cookbook, we have the space to explore these ecosystem libraries in more depth - at least to the extent that is universally useful for Vue developers.
Copy file name to clipboardExpand all lines: src/v2/cookbook/serverless-blog.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -286,3 +286,4 @@ An alternative pattern to consider, especially if you prefer writing only in Mar
286
286
## Wrap up
287
287
288
288
That's it! You now have a fully functional CMS-powered blog running in your app. We hope this tutorial was helpful and made your development experience with Vue.js even more enjoyable :)
0 commit comments