|
| 1 | +// With proper loader configuration you can load, |
| 2 | +// pre-process and insert css directly with require(). |
| 3 | +// See webpack.config.js for details. |
| 4 | +require('./main.styl') |
| 5 | + |
| 6 | +var Vue = require('vue'); |
| 7 | + |
| 8 | +var a = Vue.component('user-profile', { |
| 9 | + template: '<li {{view}}>{{user.name}} {{user.email}} {{user.msg}} {{parents}}</li>', |
| 10 | + props: ['parents'], |
| 11 | + data: function() { |
| 12 | + return { |
| 13 | + msg: '我的测试' |
| 14 | + } |
| 15 | + }, |
| 16 | + |
| 17 | + computed: { |
| 18 | + msg: { |
| 19 | + set: function() { |
| 20 | + alert(2) |
| 21 | + }, |
| 22 | + get: function() { |
| 23 | + alert(1) |
| 24 | + } |
| 25 | + } |
| 26 | + }, |
| 27 | + |
| 28 | + compiled: function() { |
| 29 | + this.$log(this) |
| 30 | + }, |
| 31 | + created: function() { |
| 32 | + this.$dispatch('child-created', this) |
| 33 | + } |
| 34 | +}) |
| 35 | + |
| 36 | + |
| 37 | +var app = new Vue({ |
| 38 | + el: '#app', |
| 39 | + data: { |
| 40 | + view: 'page-a', |
| 41 | + users: [{ |
| 42 | + name: 'Chuck Norris', |
| 43 | + |
| 44 | + }, { |
| 45 | + name: 'Bruce Lee', |
| 46 | + |
| 47 | + }, { |
| 48 | + name: 'Bruce Lee', |
| 49 | + |
| 50 | + }, { |
| 51 | + name: '111e', |
| 52 | + email: '12312312312' |
| 53 | + }], |
| 54 | + parents: 'Aaron' |
| 55 | + }, |
| 56 | + |
| 57 | + created: function() { |
| 58 | + this.$on('child-created', function(child) { |
| 59 | + // console.log(child) |
| 60 | + }) |
| 61 | + }, |
| 62 | + |
| 63 | + components: { |
| 64 | + // define the main pages as async components. |
| 65 | + 'page-a': function(resolve) { |
| 66 | + require(['./views/a'], resolve) |
| 67 | + }, |
| 68 | + 'page-b': function(resolve) { |
| 69 | + require(['./views/b'], resolve) |
| 70 | + } |
| 71 | + } |
| 72 | +}) |
| 73 | + |
| 74 | + |
| 75 | +console.log(app) |
| 76 | + |
| 77 | + |
| 78 | +/** |
| 79 | + * Some really crude routing logic here, just for |
| 80 | + * demonstration purposes. The key thing to note here is |
| 81 | + * that we are simply changing the view of the root app - |
| 82 | + * Vue's async components and Webpack's code splitting will |
| 83 | + * automatically handle all the lazy loading for us. |
| 84 | + */ |
| 85 | + |
| 86 | +function route() { |
| 87 | + app.view = window.location.hash.slice(1) || 'page-a' |
| 88 | +} |
| 89 | + |
| 90 | +window.addEventListener('hashchange', route) |
| 91 | +window.addEventListener('load', route) |
0 commit comments