M
M
mrSeller2021-05-05 16:55:38
Vue.js
mrSeller, 2021-05-05 16:55:38

How to use lodash.set with Vue.$set?

There is a problem: Vue.$set(obj, prop, value) incorrectly handles props like 'prop.subprop', but lodash.set() handles it perfectly, but lodash's set() does not set reactivity.

How can we solve this problem without reinventing the wheel that lodash already has?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mrSeller, 2021-05-05
@mrSeller

Solved the problem like this:

import set from 'lodash/set'

const prop = 'prop.subprop'
const rootProp = prop.split('.')[0]
const nonReactiveObject = set(this.reactiveObject, prop, value)

this.$set(this.reactiveObject, rootProp, nonReactiveObject[rootProp])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question