I'm trying to create a computed property in Vue 3 using composition API. The main purpose is to know if filter object has changed since the component has been mounted.
In order to accomplish that, I'm using lodash to compare the original const filterObj against the mutated const filter.
Since filter is a proxied object, I found that using toRaw removes the proxy wrapper, in fact if I do a console.log() both objects are equal.
For some reason, the computed property always returns false.
Please note this an extract of the whole component. The filter object is correctly being mutated by template inputs and dropdowns.
<script>
import { ref, computed, toRaw } from 'vue'
import _ from 'lodash'
const filterObj = {
dateFrom: null,
dateTo: null,
category: null,
createdBy: null,
updatedBy: null
}
export default {
setup() {
const filter = ref(filterObj)
const isFiltered = computed(() => !_.isEqual(toRaw(filter.value), filterObj))
return {
isFiltered
}
}
}
</script>
Edit: I found that doing const filter = ref(filterObj) is in fact making filterObj reactive. So any advice about any different approach on how to handle this will be appreciated