Skip to content
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

Vue面试题 #4

Open
WangYang-Rex opened this issue Feb 7, 2017 · 0 comments
Open

Vue面试题 #4

WangYang-Rex opened this issue Feb 7, 2017 · 0 comments

Comments

@WangYang-Rex
Copy link
Owner

WangYang-Rex commented Feb 7, 2017

过滤器fitler 如何使用

//全局 注册
Vue.filter('my-filter', function (value) {
  // 返回处理后的值
})
//组件 注册
new Vue({
  // ...
  filters: {
    fillLogoSrc: function (value) {
    }
  }
})
//使用
<img  :src="item.logo | fillLogoSrc" alt="">

调试

Vue Devtools

注册组件

Vue.component(tagName, options)

组件的生命周期

beforeCreate -> created(在这里进行初始化操作,调用方法或请求api) -> beforeMount -> mounted -> (beforeUpdate -> updated) -> beforeDestory -> destoryed

组件的data、props和store.state有什么区别,是否可修改,如何修改

组件的state是组件自身缓存的数据,用this.state=进行修改
props是父组件传递下来的数据,子组件无法进行修改
store.state是store中存储的状态,可以修改,通过调用store的mutation进行修改

父组件和子组件之间通信

父组件->子组件:props传递数据,子组件watch props进行监听,或者通过监听store的state改变
子组件->父组件:自定义事件,父组件用v-on绑定自定义事件,子组件通过this.$emit('increment')进行触发;父组件的props传递function,子组件进行调用;通过监听store的state改变

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant