Vue--使用lodash--方法/实例

原文网址:Vue--使用lodash--方法/实例_IT利刃出鞘的博客-CSDN博客

简介

        本文介绍Vue整合lodash的方法。

安装依赖

npm i lodash -P

使用

法1:挂到原型链

1.放到Vue原型链

在main.js添加如下代码

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

2.使用

let newObj = _.cloneDeep(obj);

法2:使用时import

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

<script>
import _ from 'lodash'

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

法3:使用时require

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

<script>

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

猜你喜欢

转载自blog.csdn.net/feiying0canglang/article/details/126728599
今日推荐