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
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,4 +35,53 @@ All Vue.js ViewModels and their raw `$data` can be serialized with `JSON.stringi
35
35
36
36
By using Component, Vue.js entities (ViewModel constructors, directives, filters) within a large project can be split into separate CommonJS modules. When a Component-based project is built without the `standalone` flag, it will expose its `require()` method, granting access to all these internal modules. This makes it quite easy to write browser unit tests - just include the test build and require the module you want to test.
37
37
38
+
The best practice is to export raw options / functions inside modules. Consider this example:
39
+
40
+
```js
41
+
// my-component.js
42
+
module.exports= {
43
+
created:function () {
44
+
this.message='hello!'
45
+
}
46
+
}
47
+
```
48
+
49
+
You can use that file in your entry module like this:
50
+
51
+
```js
52
+
// main.js
53
+
var Vue =require('vue')
54
+
55
+
var app =newVue({
56
+
el:'#app',
57
+
data: { /* ... */ },
58
+
components: {
59
+
'my-component':require('./my-component')
60
+
}
61
+
})
62
+
```
63
+
64
+
And you can test that module like this:
65
+
66
+
```js
67
+
// Some Mocha tests
68
+
// using a non-standalone build of the project
69
+
describe('my-component', function () {
70
+
71
+
// require exposed internal module
72
+
var myComponent =require('my-project/src/my-component')
0 commit comments