VueJS 3 - V-model not updating the initial data value - vuejs3

I read all the similar topics in here and still can't tell what's wrong...
The v-model in not making the data reactive.
I’m using vue#3.2.31 with Chromium browser version 88 on Linux and I have the following code:
< input min=“1” id=“run-times” v-model.number=“runTimes”/>
with
data() { return { runTimes: 1, }; },
The strange thing is that only on this browser, the v-model is not updating the initial value of runTimes.
It is not only on this part of code but on all codes where I use v-model.
On all other browsers everything is working correctly tested it with Windows, MacOS and Android.
Have anyone had any issues with the update with v-model?
Thanks in advance

why v-model.number=“runTimes”?,
It should just bev-model=“runTimes”

It turns out, that there is a virtual keyboard extension, which does not fire the correct events in order the reactivity to work.
I'm still trying to see a solution without reworking the code, but in the end, it could be done getting the value from the element itself when you want to use it.

Sometimes some browsers don't support reactive v-model updating, especially mobile browsers. In this case you can use :value="yourModelValue".
For example:
<input type="text" :value="myValue" #input="inputData($event)">
export default {
data() {
return {
myValue: '',
}
},
methods: {
inputData($event) {
// Value will update reactively
$event.target.value;
}
}
}

Related

How to clear local storage before running each test in WebdriverIO?

I am writing tests for a React based web tool. So I want to clear all local storage such as login information etc. before each test. I have majorly worked in Cypress, where this was just a simple command.
cy.clearLocalStorage();
I am now using WebdriverIO and this is the approach that I was trying out (in the test file).
afterEach(() => {
browser.executeScript('window.localStorage().clear()');
});
However, this doesn't seem to be working. Moreover, I would prefer a global solution, something that I don't have to write in each test. Thanks in advance for the help.
From the WebdriverIO Docs:
// remove the storage item for the given key
client.localStorage('DELETE', 'someKey');
// clear the storage
client.localStorage('DELETE');
You can clear localStorage by running this preset function.
You were almost right in your assumption. I'd suggest using official docs to eliminate minor errors.
Instead of executeScript use https://webdriver.io/docs/api/browser/execute.html
localStorage is not a function, see https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
So it should be
afterEach(() => {
browser.execute('window.localStorage.clear()');
});
P.S.
Assuming you are using WebdriverIO 5 or above.
So, after a lot of time, we realized the problem.
The cy.clearLocalStorage() cleans only the local storage under the baseUrl definition.
If you would like to open multiple pages, you have to explicit define the clearing in the cy.visit() call, like that:
cy.visit(`subdomain.another.domain`, {
onBeforeLoad(win) {
win.localStorage.clear();
},
});
In this case, the local storage for the exact domain, will be deleted.
I hope, this workaround helps.

How to update without overwriting children?

consider this existing data in a Firebase Realtime Database
db.ref('path/to/child').once('value')
{
"data":{
"this":"value",
"that":"value"
}
}
consider this set operation to the original data
db.ref('path/to/child').update({"data":{"this":"newValue"}})
{
"data":{
"this":"newValue",
}
}
how do we perform an update so that the unchanged data is preserved
db.ref('path/to/child').foo({"data":{"this":"newValue"}})
{
"data":{
"this":"newValue",
"that":"value"
}
}
Right now, your code is telling Firebase to update the entire data child under path/to/child. Instead, you should reference the most deep path to the final child node you want to update:
db.ref('path/to/child/data').update({"this":"newValue"})
Note that I've put data in the reference, instead of the object to update.
I had the same issue but the example above didnt work. I came to the same conclusion based on the docs which also didn't work. It still overwrote the content in "data".
Testing with a slash after data (in my case the object key) worked for me. Maybe I'm still misunderstanding something about how this works, but thought I'd add this incase anyone else hit the same issue. If I'm wrong, please explain.
This did work exactly as I expected.
db.rev('path/to/child/data/').update({"this": "newValue")
// almost exact path I use on some random test data
// path -> root/userid/list/listid/
db.rev('user/2FsJBrxZHQFff61QkMIuTV49KBUcQ2/list/MOwh_FwDmlKbxsfUmZS/').update({"name": "newValue")

Exception from Tracker recompute function

I have a template helper that access a collection in my app., but I have turned off reactivity:
Template.homeBoxGroupsTpl.helpers({
boxes: function () {
return Boxes.find({},
{
sort: {
order: 1
},
reactive: (Session.get("homeCanvasTplReactive") || false)
}
);
}
});
After I insert a new element on my page, that in turn updates the collection, Meteor will throw an error in the browser console:
Error: Exception from Tracker recompute function: reporters.js?1429904535194:67
Error: Error: Bad index in range.getMember: 16
at DOMRange.getMember (http://tidee-vm/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:586:11)
at http://tidee-vm/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2727:45
at Object.Tracker.nonreactive (http://tidee-vm/packages/tracker.js?6d0890939291d9780f7e2607ee3af3e7f98a3d9c:593:12)
at Object.Blaze.Each.eachView.onViewCreated.eachView.stopHandle.ObserveSequence.observe.changedAt (http://tidee-vm/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2721:17)
at http://tidee-vm/packages/observe-sequence.js?0532a9dd76dd78f543eb4d79a1e429df186d8bde:313:21
at Function._.each._.forEach (http://tidee-vm/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:164:22)
at diffArray (http://tidee-vm/packages/observe-sequence.js?0532a9dd76dd78f543eb4d79a1e429df186d8bde:299:5)
at http://tidee-vm/packages/observe-sequence.js?0532a9dd76dd78f543eb4d79a1e429df186d8bde:147:9
at Object.Tracker.nonreactive (http://tidee-vm/packages/tracker.js?6d0890939291d9780f7e2607ee3af3e7f98a3d9c:593:12)
at http://tidee-vm/packages/observe-sequence.js?0532a9dd76dd78f543eb4d79a1e429df186d8bde:121:15
Any ideas how to debug this, or is it a Meteor issue?
Meteor's error messages are horrible in all browsers but Chrome, because Meteor expects stack traces to include the error messages, but this is only done by Chrome. I hate to say this, but you'll probably have to use Chrome when debugging a Meteor app. :(
I do not have the solution, but I too encountered the same error, and was able to solve for my case, so posting it, hoping it helps you debug the issue (although this hardly seems to be of any help). The cause was use of .length. I had a large array (name of array: data), and to make it short (decrease length of arrray), I was assigning data.length = 5, which was somehow causing the error, and meteor helper did not work as expected. Removing that line worked for me, and I accomplished shortening of array by a for loop, and storing first five elements in a different variable.
I have faced similar problem too :(
I was able to resolve it by giving unique names to Tempaltes, its corresponding Helpersobject's methods in .js file and Mongo DataBase object(s) names.
Hope it might work for you too :)
For me, I was getting this error from it saying ReactionProduct.selectedVariant() is null on one of Meteor's cycles.
I just handled the null case with:
if (ReactionProduct.selectedVariant() === null) {
return;
}
and it's working out for me.

Where did this $ne come from for this find method?

Given the following Meteor code helper from the websites "Try Meteor" tutorial:
// Add to Template.body.helpers
incompleteCount: function () {
return Tasks.find({checked: {$ne: true}}).count();
}
I get pretty much everything about this code except for this arbitrary looking $ne thing. I've seen this before with Meteor examples and I don't get it: What does $ne represent? Where did $ne come from?
$ne means not equal to.
It is preferable to use this instead of {checked: false} since it also includes the ones where the checked attribute isn't in the document {} and the case where {checked: null} as both of these are cases where checked isn't equal to true & are also not false.
This way if you have a fresh document without any attributes it would also be a result of the query.

error since update to Meteor Version 0.4

i have a template with list of input-elements. their value is the title-element of an document. The input-elemnts have an keyup-event, so that when i wrote in the input-element, the title will updated. when i focus the input-elemnt, the Session-variable selectedDoc is set with the id of the document. until then it works. In another template i have a following function:
Template.content.isSelected = function () {
return !Session.equals("selectedDoc",null) ? 'small' : '';
}
When i used the function above in my code, the following error occurs.
when i focus an input-element and write something, after the first letter the the focus disappeared. the error occurs only by the first time, i focus an input-element.
what am I doing wrong? with Version 0.3.9 everything worked well.
thanks
What am I doing wrong?
You're not following Meteor or reading the changelog, so you haven't noticed the API changes.
If you read them, especially Spark, and adapt your code accordingly; your code will work on 0.4.

Resources