Original URL: Vue--using lodash--methods/instances - Programmer Sought
Introduction
This article describes how Vue integrates lodash.
Install dependencies
npm i lodash -P
use
Method 1: Hang on to the Prototype Chain
1. Put it in the Vue prototype chain
Add the following code in main.js
import _ from 'lodash'
Vue.prototype._ = _
2. Use
let newObj = _.cloneDeep(obj);
Method 2: import when using
<template>
<div class="app-container">
</div>
</template>
<script>
import _ from 'lodash'
export default {
name: 'InstanceList',,
methods: {
test() {
let newObj = _.cloneDeep(obj);
}
}
</script>
Method 3: require when using
<template>
<div class="app-container">
</div>
</template>
<script>
export default {
name: 'InstanceList',,
methods: {
test() {
let _ = require('lodash')
let newObj = _.cloneDeep(obj);
}
}
</script>