Send the input's value to v-model

Is there a way to automatically pass the value of the input into the v-model? Thank you :)

Here is the code snippet:

<input value="{{$in->id}}" v-model="upload.id">

I attempted the following in my script:

 upload: {
        bank:'',
        id:{{$in->id}},
        cash:''
  },

And in my view:

<a value="" v-model="upload.id"></a>

Answer №1

It's not possible to do it that way because v-model will always take precedence over the value attribute on the input element. The best solution would be to directly add it to your script tag.

<script type="text/javascript>
new Vue({
  data: {
    upload {
      id: {{$in->id}}
    }
  }
});
</script>

Alternatively, if you are initializing VueJS in its own JavaScript file instead of inline, you can set it as a property on the window object. For instance, in your <head> section, you can use the following code:

<head>
  ...
  <script type="text/javascript">
    window.sharedData = window.sharedData || {};
    window.sharedData.uploadId = {{$in->id}};
  </script>
  ...
</head>

This allows you to access the value in your JavaScript file like this:

data: {
  upload: {
    in: window.sharedData.uploadId
  }
}

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

Vue3's transition behavior sets it apart from Vue2. It introduces new functionalities when managing templates outside of the transition

I recently made the leap from Vue2 to Vue3, but I'm encountering some challenges with the transition behavior. Here is the original Vue2 code: https://codesandbox.io/p/sandbox/silent-surf-yth66k?file=%2Fsrc%2FApp.vue <template> <div id=&q ...

When using v-for to render components and <selection>, is there a way to customize it for just one specific instance of the component?

How can I modify the selection in each instance separately when rendering elements of an array obtained from the backend using v-for? Currently, changing one selection affects all instances due to the v-model. Is there a way to target only one selection ...

Understanding how Vue JS parses query parameters can enhance the functionality and

How can I read query values using the following code? {{$route.query.id}} I am trying to pass that id to another route, but it seems like my current approach is not working. Here's what I have: startExam(){ this.$router.push({ path:&a ...

Exploring the variations in method declarations within Vue.js

Today, while working with Vue, I came across an interesting observation. When initially using Vue, there were two common ways to define a method: methods: { foo: () => { //perform some action } } and methods: { foo() { / ...

Integrate Tailwind CSS into the bundled JavaScript file

Is there a way to integrate tailwind css into bundle js effectively? Take a look at this example involving vue 3 and tailwind 3 https://github.com/musashiM82/vue-webpack. Upon executing npm run build , it generates 3 files: app.js ABOUTPAGE.js app.6cba1 ...

Utilize Vue.js 3 and InertiaJs to Retrieve Session Information in Laravel 9

I am currently working on my initial Laravel project, incorporating Vuejs for the frontend. One of the key features of my application is allowing a Super admin to log in as a User (impersonate). By clicking on the Impersonate Button, the word impersonate g ...

What steps can I take to prevent already selected options from being chosen in a Vue.js HTML form?

Among my json data, I have a list of all inventories: { "status": true, "data": [ { "inv_id": 1, "name": "Arts" }, { "inv_id": 2, "name": "web" }, { "inv_id": 3, "name": "mobileapp" }, { "inv_id": 4, "name": "ws" }, { "inv_id": 5, ...

In Laravel with PHP, you can conclude the request by delivering a response based on specific conditions

After building a login backend, I realized the importance of checking specific conditions before allowing users to log in. However, I encountered a challenge where I needed to send different responses for each failed attempt. In the method below called in ...

Is jQuery still recommended for adding animations in VueJS?

In my component's methods object, I currently have the following code snippet: startImageAnimation() { $('.splash-image').fadeIn(1400, () => { setTimeout(function() { $('.splash-image').fadeOut(1400, () ...

Troubleshooting Cross-Origin Resource Sharing Problem in Vue.js Single Page Application and Node.js API

My Node.js Express app is set up with the cors npm package installed. Additionally, there is basic authentication enabled on the nginx server hosting my Node.js app (authentication requires an 'Authorization' key in the headers of each request). ...

Responsive left and right image styling in CSS and HTML

I have designed a landing page with fixed left and right images and content in the middle. It looks fine on desktop view, but on mobile view, the images are overlapping the content. How can I resolve this issue? <div class=" ...

The Vue3 counterpart of vNode.computedInstance

I'm currently in the process of upgrading my app from Vue2 to Vue3, but I've hit a roadblock when it comes to dealing with forms. For my form elements, such as FormInput, FormTextArea, and FormCheckbox, I have been using Single File Components ( ...

API request was blocked due to the CORS policy

As I work on developing a web app using Vue.js, users must log in to receive an API key. My post request to the API through axios includes two parameters - a name and a password. However, upon form submission, persistent errors keep appearing: OPTIONS htt ...

The functionality of SyncFusion TreeGrid ContextMenu appears to be incompatible with vue3

Having trouble implementing a context menu in my SyncFusion TreeGrid. Despite following the instructions, nothing seems to be working for me. Here's a snippet of my code: <template> <ej2-treegrid :dataSource="tabla" :context ...

Tips for implementing Bootstrap pagination in VueJS 2

Here is how my website appears: Jobs.vue: <div id="jobs" class="job-item" v-for="(item, index) in showJobs" :key="index" > <router-link ...

Steps to include a personalized error message in Laravel when utilizing Rule::in for validation

I am currently working on validating a select dropdown in Laravel using an array of agency names. I have successfully implemented the validation using Rule::in(), which returns a standard error message 'The selected agency-name is invalid'. Howev ...

The v-for loop specifically iterates over an array that relates to the current dynamic page number

I keep track of results per page number, illustrated below: <ul v-for="item in listingsData" :key="item.id"> <li>{{ item.name }}</li> </ul> <button @click="pushPrev">Push Prev Results</butt ...

Using vue-class-component: A guide on creating and setting up reactive data

I am currently working with Vue.js using TypeScript and vue-class-component. My goal is to create a custom component with reactive data. Below is the code I have so far: <template> <div> <input v-model="data.name" placeholder=" ...

Axe developer tool alert: The <ul> and <ol> elements should only have direct child elements that are <li>, <script>, or <template>

Check out this code snippet. The Li element is built into the <b-navbar> component, but I'm not sure where to locate it in the HTML. <div> <b-navbar type="light" variant="light"> <b-nav-form> < ...

Retrieve information from a JSON file within a Vue.js application rather than entering data manually

I am venturing into the world of Vue.js for the first time. I have created an app that currently relies on manually added data within the script. Now, I am looking to enhance it by fetching data from a JSON file, but I'm unsure about how to proceed wi ...