Vue framework binding

Check out this code snippet:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue</title>
</head>

<body>
    <div id="root">
        <input v-model="message" placeholder="Msg">
        <p>The message you typed is: {{ message }}</p>
    </div>
    <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8afcffefcab8a4bca4bbba">[email protected]</a>/dist/vue.js"></script>
    <script>

        new Vue({
            data: {
                el: '#root',
                message: ''
            }
        });
    </script>
</body>
</html>

Curious why the binding isn't working? I followed a tutorial here:

https://laracasts.com/series/learn-vue-2-step-by-step/episodes/1 . 

Appreciate any help. Thanks!

Answer №1

The key 'el' should be included in the object passed to the <code>Vue
constructor and not within the data object (Reference)

new Vue({
  el: '#root',
  data: {
    message: ''
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="root">
  <input v-model="message" placeholder="Msg">
  <p>Message you typed is: {{message}}</p>
</div>

Answer №2

Creating a new Vue instance with the following structure:

new Vue({
    data: {
        el: '#root',
        message: ''
 }
});

This code block should be updated to:

new Vue({
    el: '#root',
    data: {
        message: ''
    }
});

Answer №3

Your Vue object is not properly linked to the designated element.

    <script>
            new Vue({
                el: '#app',
                data: {
                    text: 'Greetings Earthlings!'
                }
            });
    </script>

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

Alter the background color upon clicking using ng-click

I am a beginner in using Angular, and I am currently working on a CodePen project. My goal is to change the background color of another div based on the color of the button clicked by the user at the bottom navigation. However, I am uncertain about the bes ...

Postman sends requests by utilizing AJAX and adhering to the same origin policy

I recently came across a Chrome extension called Postman that has proven to be incredibly useful. This tool is particularly handy for those working with RESTful applications. One thing that has puzzled me is how Postman is able to successfully send POST r ...

The React.js .map function encountered an error while trying to map the results from Firebase

As a newcomer to the realm of React and Firebase, I find myself struggling with arrays and objects. It seems like the way my data is formatted or typed does not play well with the .map method. Despite scouring Stack Overflow for answers, none of the soluti ...

How can I protect my security_access_key in a React.js application?

For security reasons, I am hesitant to import the security_access_key directly into my application. I attempted to access it through an environment variable like so: Step 1: Added the security_access_key to the .env file security_access_key=abc123 St ...

Tips for retrieving a value from a callback function?

How do I return a value from a callback function? The following code snippet is what I have: function storeData(data) { const id = "5f354b7470e79f7e5b6feb25"; const body = { name: "john doe" }; bucket.insert(id, body, (error, r ...

Guide to integrating an element-ui component within a vuetify component

I recently started working with Vue.js and incorporated two libraries into my project: Element-UI and Vuetify. I added an Element-UI component called la-table to my template, which consists mostly of Vuetify components. However, after integrating this co ...

Creating custom functions in jQuery and utilizing them within other functions

I have a specific piece of code that I need to execute in two different locations, so I am considering placing it inside a function and calling that function in both places. However, I'm unsure of how to achieve this using jQuery: Could anyone provi ...

Acquire the content of a nested element using jQuery

I have a navigation list with separate headlines and text for each item. The goal is to switch the main headline and paragraph of text when hovering over a navigation item. CodePen Example Currently, my code displays all text. I only want to display the ...

Uncomplicating Media Queries in Styled Components with the Power of React.js and Material-UI

My approach to handling media queries in Styled Components involves three distinct functions. One function handles min-width queries, another deals with max-width, and the third caters to both min-width and max-width scenarios. Let me walk you through eac ...

The google analytics tag is failing to function properly after implementing ajax on the

I am currently utilizing Google Analytics to track all events on my website. I have noticed that when the gtag scripts are directly embedded into the HTML, everything works perfectly fine (I always verify the events in Google Analytics). However, after i ...

I am currently attempting to authenticate a user with passport.js, however, I am encountering an issue as the server is returning a status of 400 (Bad Request)

After successfully registering a user and saving it into the database, I encountered a 400 (Bad Request) error when trying to authenticate the user. For authentication, I am utilizing passport.js, passport-local, passport-local-mongoose. Below is the sni ...

The data does not display when using ng-repeat in AngularJS

I created a filter using AngularJS but I am experiencing some issues with displaying the information. Although the filter is functioning correctly (you can verify by checking '$scope.showItems.length' which shows that it returns data), when I se ...

Creating a clone of a JavaScript object based on an already existing JavaScript object

Can someone help me with this coding issue? var originalObject = { method1: function() { // Do something }, method2: ['a','b','c'], method3: 1234 } I am trying to create a new object based on the orig ...

JavaScript function defined by the user in Node.js

Just dipping my toes into the world of NodeJS. Anyone know how to run a custom JavaScript function in NodeJS? Appreciate the help! ...

Using Javascript regex for extracting JSON string content including property values within HTML code

I have data in the following format that is not valid JSON. I am trying to convert it using regex, but the parse won't go through. For more details, refer to this question which I've tried. The problem lies in the fact that the response string a ...

Please provide values in the input box, with each value separated by

I attempted the following code: success: function (result) { for (var i = 0; i < result.d.length; i++) { var emails = new Array(); emails = result.d[i].Emailid; alert(emails); $("#EmailCC").val(emails); ...

Having trouble executing cucumber tests using protractor

Whenever I run my tests, I keep encountering the error: TypeError: e.getContext is not a function I am utilizing examples from https://github.com/cucumber/cucumber-js, making some modifications in world.js (to resolve timeout issues) Application versions ...

"Effortless method of augmenting an array based on a specific identifier using

I am currently working on updating an existing array in react using the useState hook. The goal of the function below is to update the array by id, specifically targeting the 'inspections' array within the data. However, instead of adding a new i ...

Swap all occurrences of an array within a given string with a different array

I'm currently developing a JavaScript applet that involves replacing array entries in a given string with elements from another array. Here is the code I have so far: const str = "Lion, Unicorn, Unicorn"; const arr1 = ["Lion", &quo ...

Does the Angular CanLoad guard only trigger once during the initial lazy load?

Recently, I've come across an interesting issue within my Angular application that consists of lazy-loaded modules. In one specific module, there is a guard in place to verify if the user decoded from the JWT token is a system admin. If the user meet ...