Vue简洁之道

Vue 简化代码

下述代码是从组件中抽取出来的;

1
2
3
4
5
export function fillParagraphText() {
let nodes = this.$refs.content.childNodes;
let arr = paragraphTextArr(nodes);
this.$store.commit("paper/fill", { paperId: this.paperId, chse: this.chse, arr });
}

我们希望下述函数体内的this指向依然是原来的组件;只需在组件的method中接收上述函数即可;

1
2
3
methods: {
fillParagraphText,
}

因为javascript,this 它是动态的,this 由调用它的对象决定;

打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2022 Jie Shen
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信