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: source/guide/application.md
+21-21Lines changed: 21 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -3,32 +3,32 @@ type: guide
3
3
order: 13
4
4
---
5
5
6
-
Vue.js is designed to be as flexible as possible - it's just an interface library that doesn't enforce any architectural decisions. While this can be very useful for rapid prototyping, it could be a challenge for those with less experience to build larger scale applications with it. The following is an opinionated perspective on how to organize larger projects when using Vue.js.
Although the standalone build of Vue.js can be used as a global, it is often better to utilize a modularized build system to better organize your code. The recommended approach of doing so is by writing your source code in CommonJS modules (the format used by Node.js, and also the format used by Vue.js source code) and bundle them using [Browserify](http://browserify.org/)or[Webpack](http://webpack.github.io/).
In a typical Vue.js project we will be breaking up our code into many small components, and it would be nice to have each component encapsulate its CSS styles, template and JavaScript definition in the same place. A bonus for using the previously mentioned build tools is that they both provided mechanisms to transform the source code before bundling them together, and with a bit of pre-processing we can write our components like this:
If you are into pre-processors, you can even do this:
23
+
如果你有预处理程序,你甚至可以这样写:
24
24
25
25

26
26
27
-
This is achieved via using the [Vueify](https://github.com/vuejs/vueify)transform for Browserify, or with [Vue-loader](https://github.com/vuejs/vue-loader)for Webpack.
With this mechanism it's very easy to leverage standalone routing libraries such as [Page.js](https://github.com/visionmedia/page.js)or[Director](https://github.com/flatiron/director).
All Vue instances can have their raw `$data` directly serialized with `JSON.stringify()`with no additional effort. You can use any Ajax component you like, for example [SuperAgent](https://github.com/visionmedia/superagent). It also plays nicely with no-backend services such as Firebase.
Anything compatible with a CommonJS-based build system works. A recommendation is using the [Karma](http://karma-runner.github.io/0.12/index.html) test runner together with is [CommonJS pre-processor](https://github.com/karma-runner/karma-commonjs)to test your code modually.
62
+
任何兼容 Common-JS 的构建系统都可以。建议使用 [Karma](http://karma-runner.github.io/0.12/index.html) test runner 结合 [CommonJS pre-processor](https://github.com/karma-runner/karma-commonjs)对你的代码进行模块化测试。
63
63
64
-
The best practice is to export raw options / functions inside modules. Consider this example:
64
+
最佳实践是暴露出模块内的原始选项/函数。考虑一下这个示例:
65
65
66
66
```js
67
67
// my-component.js
@@ -72,7 +72,7 @@ module.exports = {
72
72
}
73
73
```
74
74
75
-
You can use that file in your entry module like this:
75
+
你可以在你的入口模块中如下使用这个文件:
76
76
77
77
```js
78
78
// main.js
@@ -86,7 +86,7 @@ var app = new Vue({
86
86
})
87
87
```
88
88
89
-
And you can test that module like this:
89
+
然后你可以如下测试该模块:
90
90
91
91
```js
92
92
// Some Jasmine 2.0 tests
@@ -104,8 +104,8 @@ describe('my-component', function () {
104
104
})
105
105
```
106
106
107
-
<pclass="tip">Since Vue.js directives react to data updates asynchronously, when you are asserting DOM state after changing the data, you will have to do so in a `Vue.nextTick` callback. Alternatively you can set `Vue.config.async = false` during tests, so you can assert the DOM state synchronously right after the data change.</p>
107
+
<pclass="tip">因为 Vue.js 指令异步反映数据的更新,当你需要在改变数据之后断言 DOM 的状态时,你需要在一个 `Vue.nextTick` 回调里完成断言。另外你可以在测试中设置 `Vue.config.async = false`,这样你就可以在数据改变之后同步断言 DOM 的状态了。</p>
108
108
109
-
## An Example
109
+
## 一个示例
110
110
111
-
The [Vue.js Hackernews Clone](https://github.com/yyx990803/vue-hackernews)is an example application that uses Browserify + Vueify for code organization, Director.js for routing, and HackerNews' official Firebase API as the backend. It's by no means a big application, but it demonstrates the combined usage of the concepts discussed on this page.
0 commit comments