Where is the ideal location to store non-component data properties in Vue.js?

Currently, I am in the midst of a Vue.js project where components are predominantly used. However, there are moments when I simply need to incorporate some Vue.js syntax without creating an entire component.

Since I am not utilizing the render function as usual, the HTML content that Vue attaches to is not completely overwritten, allowing me to seamlessly integrate Vue.js syntax into existing HTML elements.

new Vue({
    el: '#vue',
    name: 'Vue root',
    data: {
      store
    },
    components: {
        Example
    }
});

An instance of adding Vue.js syntax to existing HTML would be maintaining synchronization between two inputs, for instance:

Form one on index.html

<input type="text" attributes... v-model="store.arrival">

Form two on index.html

<input type="text" attributes... v-model="store.arrival">

Prior to introducing the store, I encountered a warning message along the lines of:

[Vue warn]: Property or method "arrival" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in root instance)

This prompted me to introduce the store as I prefer not to overcrowd the data property of my root component with these stand-alone properties floating independently in space.

While I appreciate the flexibility of incorporating Vue syntax into existing HTML, it raises concerns about best practices.

Is there a more efficient way to store these variables than within the store (which may become cluttered quickly)? Alternatively, should I consider transitioning everything to components? Yet, this approach poses challenges as I will need to convert PHP variables to JavaScript if required.

I hope my explanation is coherent. Thank you for taking the time to read and feel free to request additional information if necessary.

Cheers.

Answer №1

It appears that you may be questioning the use of the data property in Vue rather than a component, or adding Vue directives to HTML within your Vue element.

There is nothing inherently wrong with this. In fact, the Vue documentation's getting started page demonstrates this practice as a way to easily integrate Vue with different web frameworks. If anyone criticizes this approach, their opinion may not carry much weight in the grand scheme of things.

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

What is the recommended approach for embedding scripts within Angular templates?

I am working on an Angular SPA that consists of multiple tabs, each served by templates. Depending on the tab, different scripts (both local and CDN) are required. Therefore, I am looking for a way to load these scripts only when they are needed, which mea ...

JavaScript and HTML code for clipboard functionality without the need for Flash

My challenge lies in creating a grid with numerous columns and data. The user has expressed the desire for a copy to clipboard button that will allow them to easily copy the data. Can anyone suggest ways to implement Copy to Clipboard functionality withou ...

What is the best way to exclude a specific key when adding JSON objects to an array?

I'm facing a challenge with a JSON array of objects that contains other arrays of objects. The structure of this array is not fixed, making it difficult for me to delete specific elements like delete mainArray[0].obj.subobj[1].objToOmit; In my progra ...

Javascript use of overlaying dynamically generated Canvases

Currently, I am developing a game to enhance my skills in HTML5 and Javascript. In the beginning, I had static canvases in the HTML body but found it difficult to manage passing them around to different objects. It is much easier for me now to allow each ...

Rearrange lists by dragging and dropping them according to specific criteria

In my AngularJS project, I am utilizing the angular-drag-and-drop-lists library from here to create two lists with the following functionalities: Dragging items from list A to list B Dragging items from list B to list A Reordering items in list A Reorder ...

How to insert a hyperlink into a Vuetify v-data-table?

I've been diving into the world of vue.js and Vuetify, slowly discovering its benefits. I want to make the emails and website in my v-data-table clickable links but I'm struggling to make it work. This is how my v-data-table looks: <v-data-ta ...

Nuxt 2.5 and higher do not recognize the definition of Global

After utilizing Nuxt 2.1 in my app, I proceeded to upgrade it gradually and everything was fine until Nuxt 2.4. However, starting from version 2.5 and above, production builds are breaking with an error stating global is not defined. The location of the e ...

Enhance the v-autocomplete dropdown with a personalized touch by adding a custom

Currently utilizing the v-autocomplete component from Vuetify, and I am interested in incorporating a custom element into its dropdown menu. You can see the specific part I want to add highlighted with a red arrow in this screenshot: This is the current s ...

What is the process for linking an HTML document to another HTML document within a div using jQuery?

Check out my HTML code: <!DOCTYPE html> <html> <head> <title>Hilarious Jokes!</title> <meta charset="utf-8"> <link href="final%20project.css" rel="stylesheet"> <script src=" ...

Issue with AngularJS in Internet Explorer 7: "querySelector" property or method not supported by object

Incorporating angularjs into an existing asp.net project has presented a challenge due to the project's dependency on IE 7 compatibility mode. Upon running the project, an error from the angularjs file was encountered: Object doesn't support pro ...

Generating an interactive button click feature within a cell of a data table

Can someone help me figure out why I am getting a SyntaxError when trying to trigger a function in a datatable cell using an onclick event on a button? The button is successfully created, but the error occurs when clicking it. The problem seems to lie wit ...

Is there a way to implement word wrapping in li text without making any changes to its width

Is there a method to wrap the content inside li elements without modifying their width? As an illustration, consider the following structure - <ul> <li>Text Example</li> <li>Text Example</li> <li>Text Exampl ...

Use the regex tag in a React component to find a specific tag by name within two different possible

Looking for a regex that can identify <Field ...name="document"> or <FieldArray ...name="document"> within a multiline text string so they can be replaced with an empty string. The text string is not formatted as HTML or XHTML, it simply conta ...

IE/Firefox returning empty value for Ajax requests

After spending two days trying to solve the issue, I still can't figure out why this code is failing in IE (v11) and Firefox while working fine in Chrome. I have read many questions on similar topics involving caching problems with multiple Ajax call ...

What is the best way to test a React component that includes a Router, Redux, and two Higher Order Components using Jest and Enzyme?

I'm currently facing a challenge with this issue. I have a React Component that is linked to React Router 4 and Redux store, and it's wrapped by two HOCs. It may sound complicated, but that's how it was implemented. Here's the export st ...

The matMul function encountered an error due to a mismatch in the inner shapes of the Tensors. The shapes provided were 684,1 and 2,1, and the transposeA and transposeB parameters were both set

I am completely new to the world of AI and tensorflow.js. Currently, I am following a Machine Learning course by Stephen Grider. I was expecting an output after running the code below, but instead, I encountered an error. Can someone please assist me? Her ...

Issue with Redux saga not responding to action initiated by clicking on an icon

Declaration of Saga function* DoStuffInSaga({myRef}){ try { console.info("saga running"); return yield delay(1000, 1); } catch(error){ console.warn(error); } } export function* mySaga(){ yield all([ yi ...

How can I use PHP to transform a JSON object containing xy coordinates into an image?

What is the best way to convert a JSON object containing xy coordinates into an image (PNG or JPG) using PHP or JavaScript? ...

Image not located: 404 error in JavaScript

I am currently working with JavaScript and have encountered an issue. I have an array of objects that contain various data such as id, title, price, and image. I need to retrieve this data from the array in order to display it. While I am able to successfu ...

How can I configure Angular.js in Webstorm?

I'm having trouble setting up a node.js and angular.js project in webstorm as I keep encountering this error message: /usr/bin/node app/src/app.js /home/dac/WebstormProjects/web-plugin/app/src/app.js:1 ion (exports, require, module, __filename, __dir ...