How to implement dirty state in VueJs

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to implement dirty state in VueJs



I am new to VueJs and I am working on a form that I want to enable the Save button only when a change occurs at the model.


Save



My initial though is to compute a dirty function comparing initial model with current.


compute



Note: This code is not tested, it's here just for an example.


var app = new Vue(
el: '#app',
data: a:0, b:'', c:c1:null, c2:0, c3:'test',
initialData: null,
mounted(): initialData = JSON.parse(JSON.stringify(data));,
computed:
isDirty: function ()
return JSON.stringify(data) === JSON.stringify(initialData)


);



Is there a better way of doing this or is there any improvement you could suggest on the above mentioned code?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS