Look into the data with vue.js, but there's not much

1. As a newcomer to vue.js, I encountered some surprising issues while experimenting with examples. The first one arose when I assigned an id to the body tag and included the following JavaScript code:

<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="./css/semantic.css">
    <script type="text/javascript" src="js/vue.js">
    </script>
</head>
<body style="background-color:black;" id="app">
<div class="ui container" style="margin:20px;">
    <div class="ui segment">
        <h1>{{ title }}</h1>
        <p>
            {{ message }}
        </p>
    </div>
</div>

<script>
    var app = new Vue({
        el: "#app",
        data: {
            message: "Hello, world!",
            title: "How about you?"
        }
    })
</script>

</body>
</html>

The result didn't display the expected data: https://i.stack.imgur.com/Y2dUO.png


2. The second issue occurred when I defined an object in the data and referenced it within a div element – the data didn't render. Here's the code snippet:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="./css/semantic.css">
    <script type="text/javascript" src="js/vue.js">
    </script>
</head>
<body style="background-color:black;">
<div class="ui container" style="margin:20px;">
    <div class="ui segment" id="app">
        <h1>{{ article.title }}</h1>
        <p>
            {{ article.message }}
        </p>
    </div>

</div>

<script>
    var app = new Vue({
        el: "#app",
        data: {
            article{
                message: "Hello, world!",
                title: "How about you?"
            }
        }
    })
</script>

</body>
</html>

I'm left wondering if there might be conflicts between using semanticUI and vue.js.

Answer №1

One recommended approach is to establish a top-level div#app, as shown below:

var app = new Vue({
    el: "#app",
    data: {
        message: "Hello, world!",
        title: "How about you?"
    }
})
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.min.js"></script>
<body style="background-color:black;">
<div id="app"><!-- just a wrapper for vuejs -->
  <div class="ui container" style="margin:20px;">
      <div class="ui segment">
          <h1>{{ title }}</h1>
          <p>
              {{ message }}
          </p>
      </div>
  </div>
</div>
</body>

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

How can a JavaScript file interact with a backend without needing to specify the URL in the compiled code, thanks to webpack?

Currently, I am working on a React application with webpack. After compiling the code using the command webpack --mode production && webpack --config webpack.config.prod.js I utilize a .env.prod file to specify the variable REACT_APP_BASE_URL, wh ...

Rearranging table rows with jQuery based on numerical values within child elements

I require assistance in sorting the rows of a table based on the numbers within certain anchor tags. Below is an example of the table structure: <table id="sortedtable" class="full"> <tbody> <tr> <th>Main tr ...

The getInitialProps function in Next.js is not functioning properly in mobile browser environments

My app runs perfectly on desktop without any errors. However, when I switch to a mobile device, I noticed that the pages fail to trigger the getInitialProps method on the client side, only if I navigate through the Link component. This is my code: return( ...

Transfer an Array of Objects containing images to a POST API using Angular

Looking to send an array of objects (including images) to a POST API using Angular and Express on the backend. Here's the array of objects I have: [{uid: "", image: File, description: "store", price: "800"} {uid: "f ...

How does the call method on array.prototype.includes work with arguments x and y?

Curious about the functionality of array.prototype.includes.call(x, y);. Discovered that includes() confirms if an array has the specified value and provides a true or false result. Learned that call() invokes this alongside any optional arguments. The ...

As the user types, automatically format the input field for a seamless and intuitive experience

My current application is running on Angular 1.3.10 I have implemented a jQuery function to automatically add a backslash to the expiration input field once the user types the third number. Although it was a quick fix, I now aim to move this functionality ...

Challenges Encountered when Making Multiple API Requests

I've encountered a puzzling issue with an ngrx effect I developed to fetch data from multiple API calls. Strangely, while some calls return data successfully, others are returning null for no apparent reason. Effect: @Effect() loadMoveList$: Obse ...

Snatching the lesson found within an iframe

Is it possible to obtain the id from an iframe using the following method? var iFrame = window.top.document.getElementById('window_<?php echo $_product->getId() ?>_content'); However, I am struggling to understand how to retrieve the c ...

Guide on how to bypass IDM when downloading a PDF file through a GET request

When I try to fetch a PDF by sending a GET request to the server and open it in a new tab, IDM interrupts my request and downloads the file instead. It changes the server response status to 204 and removes the headers. How can I prevent IDM from doing th ...

Tips for triggering the button command event using JavaScript

Is there a way to activate the button command event using JavaScript? I'm not referring to the BUTTON onclick event. ...

Unable to save a URL link in MySQL database using JSON and PHP

I am seeking some insightful advice regarding my college assignment. This time around, I have to create yearbooks using Phonegap and it's my first experience working with AJAX, JSON, and JQuery Mobile. Instead of uploading an image directly into the ...

"I'm encountering an issue with Passport.js where req.isAuthenticated is throwing an error as not

Recently I started working with node and express, along with passport.js for building an authentication feature. However, I encountered an issue while using a middleware function called "checkNotAuthenticated" in my routes. The error message I received was ...

Unable to identify the pdf file using multer in node.js

const multer=require('multer'); var fileStorage = multer.diskStorage({ destination:(req,file,cb)=>{ if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/jpg' || file.mimetype==='image/png') { ...

Running into the error message 'TypeError: Cannot invoke a class as a function' while utilizing Ziggy for Vue within Laravel

I have been searching endlessly for a solution to my issue without any luck. Here are the steps I have taken: \\Webpack.mix.js const mix = require('laravel-mix'); const path = require('path'); mix.webpackConfig({ resolve: ...

Tips for incorporating dynamic URLs in Next.js

In my current project using nextjs, I am dealing with fetching images via an API. Right now, I am receiving the "Full image path" (for example, "https://myurl.com/image/imagename.jpg") without any issue. However, I need to figure out how to fetch the image ...

Sending a series of filtered GET requests to my Express backend in a MERN (MongoDB, Express, React,

I have developed a MERN web application and am in the process of adding some GET methods to retrieve the same item for different scenarios. However, when I attempt to implement a second filter method and pass an existing parameter in my item schema, Postma ...

Employing asynchronous operations and the power of async/await for achieving seamless integration

I am currently facing an issue where I need to retrieve queries from a database stored in Postgres. A function is utilized, which employs a callback mechanism. In order to fetch rows from the database, there exists a function called getRecipesByCategoryFo ...

WordPress AJAX call results in a response code of zero

TL;DR: Unique - Go straight to code below for issue. You can view the demo I am working on by following this link. In my `functions.php` file, I first localize my script: function ajaxurl(){ wp_enqueue_script( 'product-selector', get_templ ...

Difficulty in transferring JavaScript variable to PHP

After encountering a basic issue, I learned that PHP runs server-side and executes on pageload even if the include is nestled in an AJAX callback. Initially, I could display query results by returning PHP in the JavaScript value attribute, but failing to i ...

Is there any issue that you can spot with this js / jQuery code?

Presented below is a script that prompts the user to confirm clicking a button based on a system setting. The system setting is saved in a hidden field established from the code-behind. Markup: <asp:HiddenField ID="hfConfirmOnApproval" runat="server" ...