Vue 創建自己的js工具類及導入

Vue 開發中有很多地方用到同一種方法調用,把方法做成工具類,使用起來會更方便快捷。

1.創建js 文件  datapro.js


export const deepClone = (data) => {
  return data
}

2.導入到Vue工程

main.js 上操作

import {deepClone} from './utils/datapro'
Vue.prototype.deepClone = deepClone
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

3.在需要數據拷貝處使用

    handleEdit (index, item) {
      let obj = deepClone(item)
      this.$emit('event', 'edit', obj)向父組件傳遞數據
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章