Small-scale vue iterates through elements with v-for but fails to display them

I'm really interested in Petite-vue, but I've been struggling to get even the basic functionalities to work. Unfortunately, there isn't a lot of examples or tutorials available online for petite-vue. Can anyone suggest good resources?

Right now, my main issue is trying to display the output of a JSON file. I tried defining the JSON object myself when it didn't work initially. However, I'm still not able to print the items within the for loop. Any thoughts on what might be causing this problem?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <script src="https://unpkg.com/petite-vue" defer init></script>
  </head>
  <body>
    <h1> Show Data Here:</h1>
    <div id="app">
      <div v-for="(item, index) in items" :key="index">
        <h2>{{ item.title }}</h2>
      </div>
    </div>

    <script type="module">
    import { createApp } from 'https://cdn.skypack.dev/petite-vue'

    const jsonData = [
      { title: 'Title 1'},
      { title: 'Title 2'},
      { title: 'Title 3'}
    ]

    createApp({
      data() {
        return {
          items: []
        }
      },
      mounted() {
        this.items = jsonData
      }
    }).mount('#app')
    </script>
  </body>
</html>

Answer №1

The issue arises from duplicate imports. You have two options to resolve this:

<script src="https://unpkg.com/petite-vue" defer init></script>

// and use v-scope

Alternatively, you can do the following:

import { createApp } from 'https://unpkg.com/petite-vue?module'

createApp({...})

Furthermore, petite-vue's createApp does not have a data property. Instead, you should add items directly as shown in the code snippet below:

<html lang="en">
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <h1>display data here:</h1>
    <div id="app">
      <div v-for="(item, index) in items" :key="index">
        <h2>{{ item.title }}</h2>
      </div>
    </div>

    <script type="module">
      import { createApp } from "https://cdn.skypack.dev/petite-vue";

      const jsonData = [
        { title: "Title 1" },
        { title: "Title 2" },
        { title: "Title 3" },
      ];

      createApp({
        items: jsonData,
      }).mount("#app");
    </script>
  </body>
</html>

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

using Javascript to eliminate necessary tags from concealed tabs

My goal is to dynamically remove the required tag from fields in hidden tabs when a tab is clicked using JavaScript. The presence of the required tag on unused fields causes issues with form submission, preventing data insertion into the database. Here&apo ...

Avoid activating ng-blur when ng-keydown is triggered in AngularJS

Currently, I am working on a project involving angularJS and I am facing an issue with the execution of ng-blur conflicting with ng-keydown. The problem arises because ng-keydown causes the element to lose focus at a certain point. The HTML code in questi ...

What could be causing the updated JavaScript file to not run on a live Azure website using ASP.NET MVC?

After making a minor adjustment to my JavaScript file on my deployed ASP MVC website hosted on Azure, I decided to redeploy everything. However, upon checking the resource files, I noticed that the JavaScript had indeed been changed, but the behavior of th ...

Locate element in Cypress with ID that includes a span element

Recently diving into Cypress, I'm looking to locate an element with a dynamic id that contains specific text. For instance: ... <div class="col2"> <button id="random-city-name_type-125" class="btn-secondary"> ...

Picture not showing up when loading iPhone video

My website features a video that is displayed using the following code: <div class="gl-bot-left"> <video controls=""> <source src="https://www.sustainablewestonma.org/wp-content/uploads/2019/09/video.fixgasleaks.mp4" ...

Getting Creative with Jquery Custombox: Embracing the 404

Encountering a problem with jquery custombox version 1.13 <script src="scripts/jquery.custombox.js"></script> <script> $(function () { $('#show').on('click', function ( e ) { $.fn.custombox( this, { ...

Continuously animate a series of CSS properties

Here's the code snippet I'm working with: @keyframes ball1 { 0% { transform: translateX(0px); opacity: 0%; } 50% { opacity: 100%; } 100% { transform: translateX(120px); opacity: 0%; } } @keyframes ball2 { 0 ...

The custom created THREE.Curve is not rendering correctly

Following advice from this solution, I have implemented a linearly interpolated curve in the code below: THREE.Linear3 = THREE.Curve.create( function ( points, label /* array of Vector3 */) { this.points = (points == undefined) ? [] : points; ...

Attempting to retrieve the mesh object using A-Frame's getObject3D('mesh') function results in an undefined value after several attempts

In an attempt to obtain a bounding box for an obj-model in A-frame, I came across two helpful links on stackoverflow that I will reference here: How to get bounding box information from a 3D object in A-frame? Any way to get a bounding box from a three.js ...

Ways to verify if a component triggers an event in VueJS

I am currently working with two components within my application. The Child component emits an 'input' event whenever its value is changed, and the Parent component utilizes v-model to receive this updated value. In order to ensure that the funct ...

Vue 3 - Using Emit Functionality in a Reusable and Composable File

I'm trying to utilize the emit function in my file called useGoo.ts import Swal from "sweetalert2/dist/sweetalert2.js"; export default function useModal() { const { emit } = getCurrentInstance(); function myId() { emit('id&ap ...

Surprising block of text suddenly popped up on the browser screen while I was in the middle of working on

Currently delving into the world of MERN stack and working on a simple project. Everything was going smoothly on localhost until out of nowhere, some garbled text appeared on the screen, hindering my progress. I'm completely stumped as to what this my ...

Ensure that the control button is pressed during the JavaScript onclick event function

I am looking to create a JavaScript function that checks if the CTRL button is pressed. Here is my PHP code: <tr class="clickable" onclick="gotolink('<?= base_url() . invoices/createinvoice/' . $customer->Id; ?>')"> And here ...

When I click on the delete button in the dialog box, a horizontal scroll bar appears on the page

I'm dealing with a table that includes an 'approved' column with three conditions. One of these conditions triggers the appearance of a delete button along with a confirmation dialog box made using Vuetify's dialog component. The iss ...

Creating an Angular 7 Template using HTML CSS and Javascript

I recently acquired a template that comes with HTML, CSS, and Javascript files for a static webpage. My goal is to integrate these existing files into my Angular project so I can link it with a Nodejs application to create a full-stack webpage with backend ...

Sending a string array to MVC controllers through ajax

I've been struggling to pass a list of strings from a multiple select to the controller. Despite seeming like a simple requirement, I've spent hours trying to figure it out without success. I've done some research on this but haven't be ...

I encountered an issue while attempting to download a zipped folder using an AXIOS get request, as the folder appeared

I have developed an application in NodeJs for the backend and VueJS for the frontend. I am attempting to download a zip file that is generated within the app on the frontend using the code snippet below: const downloadZIP = () => { AXIOS_REQUEST( ...

Finding a solution for the network error encountered during the execution of XMLHttpRequest.send in the specified file path (...distfxcoreservermain.js:200

Having recently delved into Angular, I successfully completed the development of my angular web application. While using ng serve for production, everything ran smoothly. However, after incorporating angular universal and attempting npm run dev:ssr or np ...

Organizing Angular project folders with the help of Node.js and Jade

I've been exploring different folder structures to ensure scalability as my project grows. While I found some useful resources, such as this one, I'm still struggling with how to actually implement these suggestions. Currently, I've adopted ...

Identifying whether a Alphabet or a Digit has been Pressed - JavaScript

I understand that it is possible to detect if a key has been pressed and identify which key was pressed using JavaScript. In order to check if a key is down or pressed, jQuery can be utilized with ease: $( "#some id" ).keydown(function() or $( "#m" ). ...