Leveraging Vuetify on a standalone .html document

I am currently working on a personal project where I am experimenting with avoiding a full npm build process. Instead, I am trying to work within a single .html file that utilizes Vue 3 and Vuetify. Below is the complete HTML code which can be simply dropped into a file, opened in a browser, and provide a visual of what I am experiencing:

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="03757666776a657a43302d372d30">[email protected]</a>/dist/vuetify.min.css">
  <script type="importmap">
      {
        "imports": {
          "vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js",
          "vuetify": "https://cdnjs.cloudflare.com/ajax/libs/vuetify/3.4.3/vuetify.esm.min.js"
        }
      }
    </script>
</head>
<body>
  <div id="app">
    <v-table>
      <thead>
        <tr>
          <th>Value</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="d in numbers" :key="d">
          <td>{{ d }}</td>
        </tr>
      </tbody>
    </v-table>
  </div>

  <script type="module">
    import { createApp, ref } from 'vue'
    import { createVuetify } from 'vuetify'

    const vuetify = createVuetify()
    const app = createApp({
      setup() {
        const numbers = ref([4, 5, 6])
        return { numbers }
      }
    })

    app.use(vuetify).mount('#app')
  </script>
</body>
</html>

As I observe Vue initiating successfully and Vuetify assets being fetched correctly, an error appears in the console which seems to indicate a sequencing issue:

[Vue warn]: Property "d" was accessed during render but is not defined on instance. 
  at <VTable> 
  at <App>

My assumption is that the template attempts to render before the setup() script populates data. Is it possible for me to achieve what I am aiming for?

Another observation is that when I forego using data and instead create a basic table with v-table, like so:

<v-table>
  <thead>
    <tr>
      <th>Col 1</th>
      <th>Col 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>R1C1</td>
      <td>R1C2</td>
    </tr>
  </tbody>
</v-table>

The rendered output is simply

<table> Col 1 Col 2 R1C1 R1C2 </table>
, without any errors appearing in the console. Notably, if I exclude Vuetify and opt for standard table tags, the table is created correctly. This issue only arises when Vuetify tries to render the v-table component.

Answer №1

Placing Vue template code directly inside the <div id="app"> results in the browser processing it before Vue has a chance to interact with it. When table elements like thead, tbody, etc. are used outside of a table structure, the browser removes them, leaving you with this:

<v-table>{{ d }}</v-table>

Due to the removal of d from the v-for, along with the tr tag, an error may occur and cause the table to break.


To address this issue, there are two solutions: either move the template code into Vue setup and keep the app mount point empty:

<div id="app"></div>

or

  <script type="module">
    ...
    const app = createApp({
      template: `
        <v-table>
          rest of the table code...
        </v-table>
      `,
      setup() {
        const numbers = ref([4, 5, 6])
        return { numbers }
      }
    })
    ...

Alternatively, using a table element instead of v-table allows Vue to replace it later using the is attribute:

  <div id="app">
    <table is="vue:v-table">
      rest of the table code...
    </table>
  </div>

There are additional concerns when templates are not utilized, refer to the in-DOM Template Parsing Caveats section of the documentation

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

The Vue.js v-on:mouseover function is not functioning properly in displaying the menu

When I hover over a LI tag, I want to display a menu. I have successfully implemented it using a simple variable with the following code: @mouseover="hoverFormsControls=true" @mouseleave="hoverFormsControls=false" However, when I attempted to use an arr ...

excess white space appears in the mobile version

I recently completed a website using both materializecss and bootstrap platforms. While I know this may not be the best practice, it worked for my needs. However, I am facing an issue with the mobile view. When I reduce the viewport size, a margin appear ...

The NW JS window loaded event fails to trigger when loading a URL, but functions properly when loading from a local

Having trouble triggering the loaded event on a live webpage compared to a local page. The loaded event fails to fire with this code: var mywin = nw.Window.open('http://www.google.com', {"frame": false}, function(testWin) { testWin.on(&apos ...

Best practices for working with child components in Vue.js using TypeScript: Steer clear of directly mutating props

I feel like I'm stuck in a loop here. Currently, I have a Vue.js 2 app set up and running with TypeScript. However, I'm encountering an issue when trying to pass data to a child component that originates from the store. <template> < ...

Session authentication mechanism designed to remain active only as long as the browser tab is open

Imagine you are developing a front-end application that utilizes a third-party API for authentication, with a successful authentication resulting in a JSON web token. What strategies would be most effective for storing this token and establishing a user s ...

What are the best practices for managing promises effectively?

Currently, in my Angular application, I am utilizing $odataresource for handling data retrieval and updates. The code snippet I am working with is as follows: var measure = $odataresource("http://windows-10:8888/ChangeMeasure/"); var myMeasure = measure ...

What is the best way to incorporate a feature that flips all choices in react-select?

I'm working with a multi-option Select component from react-select, and I need to add a special option that will invert the selected options into unselected ones, and vice versa. When this 'Invert selection' option is chosen, I don't w ...

Accessing data from localhost using Vue.js and Axios is restricted due to CORS policy and the error "Access to XMLHttpRequest" may be

Having a minor issue... Trying to retrieve a basic json file from my server for testing purposes (not an actual API). Utilizing VueJS and axios. Here is my code : getServicesAPI() { axios.get("http://51.91..../dist/API/Services.json").the ...

Unable to suppress error in AngularJS $http.get() call when using catch() method

Below is a simplified version of the code I'm working with, running in CodePen for example: var app = angular.module("httptest", []); app.controller("getjson", ["$scope", "$http", function($scope, $http) { $http.get("https://codepen.io/anon/pen/L ...

Unable to navigate through select2 dropdown if fixed div is present

I am facing an issue with select2 in my fixed div popup that acts like a modal. The problem is that when the select2 dropdown is open, I am unable to scroll the div until I close the dropdown. This becomes problematic on smartphones because the keyboard e ...

Can someone help me extract a specific portion and display the dimensions of the area?

In order for the mouse to create a selection range, simply release the mouse after making your selection. The selected area will display the values of width and height on both the X-axis and Y-axis in the designated fields. I am facing this issue and woul ...

Ways to address the problem of returning assignments

I encountered an issue while working on my code Error message: Arrow function should not return assignment no-return-assign The problematic code snippet is as follows: await DB.Place.find( match, // key to filter (err, doc) => (listOfObje ...

Configuring Dialog Placement to the Top in Material-UI

I'm in the process of creating a popup dialog, but I'm encountering an issue where the dialog pops up in the center of the page. How can I position it at the very top of the page when the popup button is clicked? Below is the code snippet: < ...

Is there a way to halt or end an interval within a function triggered by useEffect()?

I am currently working on a countdown timer script using react.js. The timer displays a 3 or 5 seconds countdown before starting, with data for these countdowns coming from another component. I am facing an issue with controlling the main countdown timer ...

Error: Unexpected syntax error in JSON parsing after importing PHP file

Encountered an unexpected error: Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data site:stackoverflow.com, which is appearing in the Firefox debug console. On my website, I have a form that triggers this function o ...

Issue with FileStreamResult not triggering download prompt after AJAX call in MVC

I am encountering an issue with my code that is triggered by the "export" li tag. It converts a FusionChart to an SVG string and then sends it to my controller via an ajax call. The problem I'm facing is that even though the controller receives the r ...

Attaching multiple elements to events in Vue.js

Can events be attached to multiple HTML elements without the use of components? Example: <ul> <li> <li> <li> <li> </ul> Is it possible to bind a click event to all <li> elements in this scenario? If so, ...

Checkbox value not being accurately retrieved by Struts2 page

I have a form that captures phone information for two different phones, with each phone having its own set of details. If the user enters the same phone number for both phones, the second checkbox is automatically checked using the JavaScript code below: ...

Developing an ASP application using the MVP pattern to return JSON data can be transformed into a S

I’m looking to incorporate the following code into a sails js Controller public JsonResult GetEvents() { //Using MyDatabaseEntities as our entity datacontext (refer to Step 4) using (MyDatabaseEntities dc = new MyDatabaseEntities()) { ...

Can we pause and resume the progress bar using Javascript in conjunction with animationPlayState?

Looking for a way to control a progress bar script that runs for 180 seconds and then redirects the browser? Check out the code snippet below. I've added an onclick event to test pausing the progress bar. My goal is to pause, reset, and adjust the dur ...