Troubleshooting: Issue with binding nested data property using bracket access in Vue3 v-model

Having an issue in Vue3 where I am unable to bind a nested property to v-model correctly.

Check out the source code below:

Template:

<div id="app">
  <span>{{level1.level2.level3}}</span> <br/>
  <span>{{level1['level2']['level3']}}</span> <br/>
  <input v-model="level1.level2.level3" /> <br/>
  <input v-model="level1.level2['level3']" /> <br/>
  <input v-model="level1['level2']['level3']" />
</div>

JS

Vue.createApp({
  data() {
    return {
      level1: {
        level2: {
          level3: "val"
        }
      }
    }
  },
  methods: {}
}).mount("#app")

<input v-model="level1.level2.level3" />
binding works

<input v-model="level1.level2['level3']" />
binding works

but

<input v-model="level1['level2']['level3']" />
binding fails

The console warning displayed is

"[Vue warn]: Template compilation error: v-model value must be a valid JavaScript member expression.

Any ideas why level1['level2']['level3'] isn't binding to v-model correctly? To me, it seems like a valid js expression.

Here is the online fiddle for reference.

Answer №1

It appears that the issue lies within Vue itself, rather than in your code. Recent developments indicate that this problem has been resolved in a commit made just over a week ago.

If you are using Vue <=3.1.1 (any version other than the current GitHub master branch), your best course of action would be to adjust how you access properties, wait for an update from Vue, or opt to rely directly on the GitHub repository's master branch (although this may not be advisable unless absolutely necessary and urgent).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Saving Backbone.js Collection as Text File on HDD & Re-importing Data

After experimenting with Backbone.js for a while, I've relied on localStorage to store most of my app data. However, I now want to explore the possibility of exporting my collection to plain text for easy backup purposes. Essentially, I envision a fea ...

Offering fields for modules, main, and browser that meet the needs of ESM, CommonJS, and bundlers

I have upgraded a number of my published npm packages to include both commonjs and esm builds. Some of these packages are meant for use in both node and the browser, and they are all compiled using webpack or rollup. Additionally, all of them are written i ...

Preventing parent requests from being triggered when a child element is clicked in Angular 2

I have a similar code structure as shown below and I am trying to achieve the behavior where clicking on the Child Div does not trigger the Parent Div click event. <div class="parentDiv" (click)="parentDiv()"> <div class="childDiv" (click)="ch ...

What could be causing the misalignment between the desired output and the response from the AJAX request

Below is a basic JavaScript file I am working with: $.ajax({ url: "is_complete.php", type: "post", success: function (data) { if(data == 1) { } alert("ok") } }) The message "ok" will only be di ...

Avoid multiple delays when clicking the identifier

I came across this code snippet: $(element).on('click', function() { $this.closest('div').before('<span id="message" style="display:none"></span>'); $('#message').fadeIn().delay(5000).fadeOut(); ...

Using VueJS with Bootstrap 4 themes: A step-by-step guide

There are various Bootstrap 4 themes available that simplify the process of styling and laying out a website. Some of these themes require specific organization of our assets folders. For example: root-folder/ ├── assets/ │ ├── css/ │ ...

IE and Firefox display different responses when encountering an empty XML document

When working with jQuery to read an XML file, I occasionally encounter the situation where the XML is empty. In this case, I anticipate that the error function (no_info) will be triggered because the file is not formatted as expected for the dataType. Int ...

The disappearance of the "Event" Twitter Widget in the HTML inspector occurs when customized styles are applied

Currently, I am customizing the default Twitter widget that can be embedded on a website. While successfully injecting styles and making it work perfectly, I recently discovered that after injecting my styles, clicking on a Tweet no longer opens it in a ne ...

A bot responsible for assigning roles never fails to remove a role when necessary

My goal was to develop a bot that automatically assigns users a role based on the language they speak in a bilingual server. However, when I tried to assign myself the Czech role, it added the role but failed to remove the rest: const Discord = require(&a ...

Obtain a multiline match using regular expressions

Is there a way to use regex to match only multi-line strings without matching single-line strings as well? Here is the current regex I am using: Regex ('|"|`)[\s\S]*?(\1) Test string "not a match" "need to match&qu ...

Enhance fullness to facial features

Creating walls by forming faces using specific points is a successful process for me. However, I am now looking to add thickness to these walls, and I am unsure of the best approach. Below is the code I currently use to create the walls: makeWall(start, ...

Exploring techniques for creating realistic dimensions in CSS

My goal is to create a responsive website that accurately displays an object with specified dimensions, such as a width of 100mm, regardless of the user's screen resolution. However, I am facing challenges in achieving this consistency across all devi ...

Organize the outcomes according to the date provided by the object's keys, and simply tally the number

Hello, I am struggling to retrieve a complex return using MongoDB and Javascript. Can someone please explain how to achieve this? Admin. Group the result by ID. User: Flatten the result. Here is an example of the data: let user = [ { _id: 123, ...

Retrieving JSON data from an API

As a beginner with Jquery JSON and API's, I am trying to work on hitting an API that returns city names in JSON format. I need to display these city names dynamically on my webpage in a list format. Can someone guide me through this process? If you w ...

What is the best way to eliminate a vertical line from the canvas in react-chartjs-2?

Can someone please lend me a hand? I've been working on a project in React JS that involves using react-chartjs-2 to display charts. I'm trying to incorporate a range slider for the chart to manipulate values on the x-axis, as well as two vertic ...

Changing the background color of .pane and .view elements in an Ionic web application using JavaScript

Looking to modify the background-color of two css selectors, .pane and .view, that are located within the ionic.css file. Despite multiple attempts to do so using JavaScript directly in the index.html file, the changes are not reflected. The code snippet ...

When making a jQuery ajax request to the Google Maps API, an error is returned stating "SyntaxError:

I'm trying to make an ajax call using jsonp to the Google Maps API v3, but it keeps ending up in the error function. In the Firefox console log, I see the following error message: SyntaxError: invalid label "results" : [ When I click on it, I can se ...

The JQuery.ajax function encountered an unexpected identifier and threw an Uncaught SyntaxError

Hey there, I'm encountering this error and I'm stumped: jQuery.ajax Uncaught SyntaxError: Unexpected identifier I'm attempting to pass some customer information to another file named "pricealarm.php" in the main directory of the FTP-Serve ...

PHP/AJAX user action history manager

Is there a library available that offers undo/redo functionality with a complete history for a web application? One possible solution could be a system using php/javascript/ajax where you can record the opposite action and variable state for each user acti ...

I'm having trouble getting my bot command handler to function properly

When it comes to my command handler, the commands function properly. However, when I attempt to include arguments like $user-info @user instead of just $user-info, it returns an error stating that the command is invalid. Code //handler const prefix = &ap ...