vue -- lodash を使用 -- メソッド/インスタンス

元の URL: Vue - lodash を使用 - メソッド/インスタンス - プログラマー募集

序章

        この記事では、Vue が lodash を統合する方法について説明します。

依存関係をインストールする

npm i lodash -P

使用する

方法 1: プロトタイプ チェーンにしがみつく

1. Vue プロトタイプチェーンに入れる

main.js に次のコードを追加します。

import _ from 'lodash'
Vue.prototype._ = _

2.使用

let newObj = _.cloneDeep(obj);

方法 2: 使用時にインポートする

<template>
  <div class="app-container">
    
  </div>
</template>

<script>
import _ from 'lodash'

export default {
  name: 'InstanceList',,
  methods: {
    test() {
      let newObj = _.cloneDeep(obj);
    }
}
</script>

方法 3: 使用時に必要

<template>
  <div class="app-container">
    
  </div>
</template>

<script>

export default {
  name: 'InstanceList',,
  methods: {
    test() {
      let _ = require('lodash')
      let newObj = _.cloneDeep(obj);
    }
}
</script>

Supongo que te gusta

Origin blog.csdn.net/feiying0canglang/article/details/126728599
Recomendado
Clasificación