New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MVVM记录 #19
Comments
vue.js
摘录
组件的应用模板 <div id="app">
<app-nav></app-nav>
<app-view>
<app-sidebar></app-sidebar>
<app-content></app-content>
</app-view>
</div>
var vm = new Vue({
// 选项
})
阅读到http://cn.vuejs.org/guide/class-and-style.html <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>vue demo</title>
<script src="./node_modules/vue/dist/vue-1.0.js"></script>
</head>
<body>
<div id="example-2">
<p v-if="greeting">Hello {{* name}}!</p>
<p v-if="greeting">Hello {{name}}!</p>
<p>{{{html}}}</p>
<p>{{ok?'yes':'no'}}</p>
<p>{{ message.split('').reverse().join('') }}</p>
<p>首字母大写“过滤器”: {{ message | capitalize }}</p>
<a :href="http://baidu.com">link</a>
<button :disabled="disabledFn">Button</button>
<button @click="clickFn">Button</button>
<div>a={{a}},b={{b}}</div>
<div>fullName: {{fullName}}; firstName: {{firstName}}; lastName: {{lastName}}</div>
</div>
</body>
</html>
<script>
var vm = new Vue({
el: "#example-2",
data: {
greeting: 1,
name: 'Vue.js',
html: '<strong>输出html</strong>',
ok: false,
message: 'hello world',
a: 100,
firstName: 'Foo',
lastName: 'Bar'
},
created: function () {
console.warn('vm is created.');
},
methods: {
disabled: function () {
console.error('disabled');
},
clickFn: function () {
alert('点击');
}
},
computed: {
b: function () {
return this.a + 1
},
// 相当于getter
// fullName: function () {
// return this.firstName + ' ' + this.lastName
// }
fullName: {
// getter
get: function () {
return this.firstName + ' ' + this.lastName
},
// setter
set: function (newVal) {
var names = newVal.split(' ');
this.firstName = names[0];
this.lastName = names[names.length - 1];
}
}
}
});
vm.$watch('name', function (newVal, oldVal) {
console.log('变化了',newVal,oldVal);
});
</script> |
vuex map的使用遇到的坑vuex的map有如下写法 import { mapGetters } from 'vuex'
export default {
// ...
computed: {
// 使用对象展开运算符将 getters 混入 computed 对象中
...mapGetters([
'doneTodosCount',
'anotherGetter',
// ...
])
}
} 其中的使用扩展符 查明原因原来是Babel的不同等级支持度不一样,需要设置不同的stage 解决方案 # 安装babel-preset-stage-2
$ npm i babel-preset-stage-2 -D // 设置.babelrc,新增了stage-2
{
"presets": [
["es2015", { "modules": false }],
"stage-2"
]
} 再次启动程序 汗!真是折腾,官网vuex没有告知这一点 |
重新看Vue.js教程得到的启示生态学习
基础
|
学习MVVM框架
The text was updated successfully, but these errors were encountered: