We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案 欢迎大家在下方发表自己的优质见解 二维码加载失败可点击 小程序二维码
The text was updated successfully, but these errors were encountered:
挂载到Vue的prototype上。把全局方法写到一个文件里面,然后for循环挂载到Vue的prototype上,缺点是调用这个方法的时候没有提示
Object.keys(tools).forEach(key => { Vue.prototype[key] = tools[key] })
利用全局混入mixin,因为mixin里面的methods会和创建的每个单文件组件合并。这样做的优点是调用这个方法的时候有提示
Vue.mixin(mixin) new Vue({ store, router, render: h => h(App), }).$mount('#app') import tools from "./tools" import filters from "./filters" import Config from '../config' import CONSTANT from './const_var' export default { data() { return { CONFIG: Config, CONSTANT: CONSTANT } }, methods: { // //将tools里面的方法挂载到vue上,以方便调用,直接this.$xxx方法名就可以了 // Object.keys(tools).forEach(key => { // Vue.prototype[key] = tools[key] // }) //将tools里面的方法用对象展开符混入到mixin上,以方便调用,直接this.$xxx方法名就可以了 ...tools }, filters: { // //将filter里面的方法添加了vue的筛选器上 // Object.keys(filters).forEach(key => { // Vue.filter(key, filters[key]) // }) ...filters } }
Sorry, something went wrong.
No branches or pull requests
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。
The text was updated successfully, but these errors were encountered: