Having trouble getting Vue JS 2.0 to display content?

When working with Vue (^2.0.0-rc.6) and Browserify, the entry point is index.js:

import Vue from 'vue'
import App from './containers/App.vue'

new Vue({ // eslint-disable-line no-new
  el: '#root',
  render: (h) => h(App)
})

The content of App.vue:

<template>
  <div id="root">
    <hello></hello>
  </div>
</template>

<script>
import Hello from '../components/Hello.vue'
export default {
  components: {
    Hello
  }
}
</script>

<style>
body {
  font-family: Helvetica, sans-serif;
}
</style>

Regarding Hello.vue:

<template>
  <div class="hello">
    <h1>\{{ msg }}</h1>
  </div>
</template>

<script>
export default {
  data () {
    return {
      msg: 'Hello Vue!'
    }
  }
}
</script>

Experiencing a blank white screen, is there something I overlooked?

UPDATE:

The entry html contains just

<div id="root"></div>
, no errors are showing up on the console logs, and I have confirmed that Hello.vue is being loaded as I see 'test' in the console log.

UPDATE 2:

Discovered the issue:

[Vue warn]: You are using the runtime-only build of Vue where the template option is not available. Either pre-compile the templates into render functions, or use the compiler-included build. (found in anonymous component - use the "name" option for better debugging messages.)

Does this indicate that I need to switch to a webpack solution? Is standard HTML not compatible in this scenario?

RESOLUTION: Import Vue from 'vue/dist/vue.js'

Answer №1

If you're searching for the answer, here's a simplified version for you:

import Vue from 'vue/dist/vue.js'
import App from './App.vue'

new Vue({
  el: '#app',
  render: h => h(App)
})

According to the author, the 2.0 standalone build includes both compiler and runtime. The default export from the NPM package will only include the runtime to allow for pre-compilation of templates with a build tool during installation.

Answer №2

If you're utilizing a build tool like browserify or Webpack, you can likely make use of single file components to prevent such errors (in single file components, templates are automatically compiled to render functions by vueify). It's highly recommended to avoid templates in other places. Consult the forum and documentation for tips on avoiding them.

However, I understand that pinpointing the templates in your project responsible for the error message isn't always straightforward. If you're encountering this issue, a temporary solution would be:

Avoid importing 'vue/dist/vue.js' (refer to the documentation: https://github.com/vuejs/vue/wiki/Vue-2.0-RC-Starter-Resources#standalone-vs-runtime-builds to understand why)

Instead, manage this in the build tool you're using.

In my case with browserify, you can create an alias using aliasify. Include the following in your package.json file:

{
  // ...
  "browser": {
    "vue": "vue/dist/vue.common.js"
  }
}

For Webpack users, it appears you need to add the following to your config:

resolve: {
    alias: {vue: 'vue/dist/vue.js'}
},

Further details can be found in the documentation: https://v2.vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only

Answer №3

When using Vue 3.4.0, you have the option to create a new file in the project's root directory.

Create a file called vue.config.js and include the following code inside:

module.exports = {
  runtimeCompiler: true
}

After adding this configuration, the next time you launch the application, you will notice:

Successfully compiled in 204ms at 20:46:46

App running at:

Answer №4

When using Brunch, I encountered a similar issue and was able to resolve it by including the following rule in my brunch-config.js file:

  npm: {
    aliases: {
      vue: "vue/dist/vue.js"
    }
  }

For more information, you can refer to the documentation at

This specific case involved creating a Vue component with a nested <template>:

<template>
  <div> hello </div>
</template>

<script>

 export default {
   name: 'Hello',
   props: {
     title: String,
   },
 }
</script>

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

Searching Text Boxes with Javascript: A Better Way to Handle Arrays

I'm struggling to implement a feature where users can search for authors in a database and be redirected to the corresponding HTML if found. Otherwise, it should display a message saying "No Author Found"... I need some assistance in getting this fun ...

Enhancing user experience with dynamic element integration in jQuery's AutoComplete feature

In order to fulfill my requirement, I need to display a few options when the user enters at least three characters in one of the input fields, which may be added dynamically as well. Since the data is extensive, I am unable to load it at the beginning of ...

Nuxt js is throwing an error stating that it is unable to locate the pages directory

I have made changes to the folder structure of my Nuxt.js project. I am encountering an issue: Error - Couldn't find a pages directory in D:\sample. How can I access the pages? .nuxt, app, node_modules, server, .eslintrc, package, package-lock ...

Add and alter a script tag within the Vue template

I am currently working on integrating a payment service into my platform. The payment service has provided me with a form that includes a script tag. This question is a follow-up to a previous query on inserting a script tag inside a Vue template. Here i ...

I am attempting to create a skybox, yet it seems like I am overlooking a crucial element

Currently, I am attempting to create a skybox but have encountered difficulties with various tutorials. Initially, I tried to use an array approach to pass parameters for the material based on a previous example, but it seems that the method has been updat ...

Navigating Angular's Credit Card Input Functionality

I am looking to limit the input capacity to 16 numbers and add a space between each set of 4 numbers. After conducting an extensive search for a credit card input that allows users to enter 16 digits with a " - " or space in between, all results were for ...

Enhance the functionality of datatables pagination click by removing and restoring it

I have a datatable set up on a webpage with numerical pagination buttons for First, Previous, Next, and Last, as well as individual number buttons. Each row in the datatable has an 'Edit' link. I want to disable the pagination functionality when ...

Where can the Path be found for Json inside App Phonegap?

Having some trouble with my Phonegap App! Everything seems to be working fine when I test it in my browser. However, once I compile it into an APK and install it on my phone, it's unable to find the JSON data. I'm a beginner in programming and a ...

Adding a third-party script after closing the body tag on specific pages in NextJS can be achieved by using dynamic imports and

In my NextJS application, a third-party script is currently being loaded on all pages when it's only needed on specific pages. This has led to some issues that need to be addressed. The script is added after the closing body tag using a custom _docum ...

What is the best way to automatically create a PDF file that includes interactive JavaScript charts?

My goal is to create a word document or PDF containing charts from various JavaScript chart libraries. I've successfully implemented these libraries on websites, but now I want to include them in my documents as well. My initial attempt involved usin ...

Leveraging jQuery within a method defined in an object using MyObject.prototype.method and the 'this' keyword

Recently, I've started exploring Object-oriented programming in JavaScript and have encountered a challenge. I'm trying to define an object like the example below, where I am using jQuery inside one of the methods. I'm curious about the best ...

Unable to assign a value to a constant within the class constructor

I'm aware that in TypeScript, readonly properties can only be assigned a value within a class constructor. However, I encountered an error while trying to do so inside the constructor of my class, specifically related to an array method handler. class ...

error : failed to establish a connection to the MongoDB database

Ensure that the first parameter passed to mongoose.connect() or mongoose.createConnection() is a string. MongooseError: The uri parameter for openUri() must be a string, but it was "undefined". Double check that the initial parameter for mongoose.connect() ...

Laravel Mix causing issues with Vue loading when extract() is used

I currently have a simple webpack.mix.js and resources/js/app.js setup in my Laravel project. Here is the code from webpack.mix.js: const mix = require('laravel-mix'); mix.js('resources/js/app.js', 'public/js') .sass(&ap ...

Divide an HTML file into separate documents upon submitting a form

Is there a way to input HTML into a text area, then upon submission, have the system read the file, identify the class selector, and separate the HTML into multiple files saved in a directory? If you have any thoughts on how this could be accomplished, pl ...

"Troubleshooting: Why is the JavaScript canvas.toDataURL method returning an

While I know this question has been asked multiple times before, I still haven't been able to find a solution. My goal is to take an image, rotate it, and place it in an HTML canvas. To achieve this, I am utilizing another canvas where I rotate the i ...

Plugin for saving inline edits in CKEditor 4

After creating a plugin for ajax save, I found the documentation confusing when it comes to implementation. How can I make the button responsive and able to save content using AJAX with PHP? Currently, I am unable to retrieve the content. Directory: /plug ...

Efficiently managing multiple database updates with PHP and JQuery

Having trouble processing multiple mySQL updates simultaneously? I have 4 select/option boxes fetching data from a db table and I want to update the database onChange using JQuery. It's working with one select module, but adding more causes issues. Th ...

npm package.json scripts not executing

Whenever I try to run npm start or npm run customScriptCommand, npm seems to not be executing anything on my project and just quickly returns a new line in the terminal. I attempted to solve this issue by uninstalling node and npm from my machine, then in ...

Nuxt failing to generate dist folder

Using docker-compose, I am building and running an SSR Nuxt.JS application with the web server being nginx. The issue arises when attempting to use nginx reverse proxy because the directory dist is not created in /app/. Below is my Dockerfile: FROM node:1 ...