Is there a way to incorporate vue samples into an independent HTML document?

Striving to broaden my knowledge of Vue, I set out to create a page with tabs inspired by one of the Vue examples available at . However, an obvious error seems to be eluding me, as I encounter a syntax issue on the line

import * as Tabs from 'vue-slim-tabs';

when viewing it in Chrome.

tabs01.html:27 Uncaught SyntaxError: Unexpected token *

I am only accessing it as a local file file:///C:/Users/USERX/Documents/git-projects/vue/tabs/tabs01.html, as my goal is to grasp the fundamental concepts. It seems that something very apparent is escaping me here because neither the import line nor the script tag import seems to work.

tabs01.html:

<html>

<head>
  <title>Tabbing test 01</title>
</head>

<body>
  <div id="app">
    <template>
      <tabs>
        <tab title="Vue">
          This is Vue
        </tab>
        <tab title="React">
          This is React
        </tab>
        <tab title="Svelte">
          This is Svelte
        </tab>
      </tabs>
    </template>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30464757d240476242234950512f2b212b">[email protected]</a>/dist/vue-slim-tabs.js"></script>

  <script>
    import * as Tabs from 'vue-slim-tabs';
    Vue.use(Tabs);
    const app = new Vue({
            el: '#app',
            data() {
                return {}
            },
          });
</script>

</body>

</html>

Answer №1

You have the option to utilize the global variable vueSlimTabs to access the plugin without needing to import it. This global variable is initialized when the vue-slim-tabs.js file is loaded as a non-module script. For instance:

<html>

<head>
  <title>Tabbing test 01</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="710704145c021d181c5c0510130231415f425f41">[email protected]</a>/themes/default.css">
</head>

<body>
  <div id="app">
    <template>
          <tabs>
            <tab title="Vue">
              This is Vue
            </tab>
            <tab title="React">
              This is React
            </tab>
            <tab title="Svelte">
              This is Svelte
            </tab>
          </tabs>
        </template>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90e6e5f5bde3fcf9fdbde4f1f2e3d0a0bea3bea0">[email protected]</a>/dist/vue-slim-tabs.js"></script>
  <script>
    Vue.use(vueSlimTabs);
    const app = new Vue({
      el: '#app',
      data() {
        return {}
      },
    });
  </script>

</body>

</html>

If the vue-slip-tabs were set up as an ES6 module, you could import it in this manner:

<script type="module">  
import * from 'https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98f8c9cd48a959094d48d989b8ab9c9d7cad7c9">[email protected]</a>/dist/vue-slim-tabs.js'  
//...
</script>

However, the current setup only allows importing as a UMD module. Therefore, if you wish to import it as an ES6 module, transpilation is necessary, which is typically handled by most vue/webpack cli setups. In this scenario, the source code undergoes transformation before being loaded by the browser.

Answer №2

Is this a compiled version of Vue or simply opened in Chrome as mentioned above?

You cannot use import without compiling Vue. Most basic example files utilize Vue's simple string template format that can be directly opened in a browser.

In order to use import, Vue must be compiled first before opening in a browser.

For more information, please refer to https://v2.vuejs.org/v2/guide/single-file-components.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

What is the best way to add a v-model modifier to a VueJS Component?

VueJS offers built-in modifiers for v-model like v-model.trim which can manipulate the binded value, such as removing whitespaces from a string. Is it possible to create a custom modifier on v-model, like v-model.myparse? Currently, I am using the followi ...

The hue of the knob is unchangeable once the server data request is made

Upon receiving data from the server request, I am unable to update the color of the knob to match the image provided at this link screencast. Below is my code: JavaScript Code $scope.options = { /* knob option */ }; $http .get(url) .then(functio ...

Position a component in relation to another component using AngularJS

Utilizing ng-show and ng-hide, I created a descriptive box that appears below text when clicked. However, there is an issue as the description box does not align directly under the text, similar to what is shown in this image https://i.stack.imgur.com/phBh ...

Express.js response.json method can be used to render both HTML and JSON content in the

I have a router that is sending JSON data to the client as shown below: router.get('/', function(req, res, next) { UserModel.selectAllUsers(function(err, vals){ if(err){ console.log(err); } res.json({d: v ...

Angular2 - Implementing Form Validation for Dynamically Generated Input Fields Based on Conditions

My goal is to create a basic form that allows users to select between two options: Local and Foreigner. If the user does not make a selection, the form should be marked as invalid. Choosing Local will make the form valid, while selecting Foreigner will rev ...

Whoops! The input buffer seems to be containing an image format that is not supported while attempting to utilize Next JS next-opt

I initially used the default Image Optimization component in my Next JS app, only to realize that the site could only be hosted on Vercel and not on other web hosting platforms. This limitation prompted me to explore the next-optimized-images package, whic ...

Exploring the integration of Vue.js and Requirejs for efficient development

After creating a new Vue.js project with vue-cli and building it using the command: vue build --target lib --name myWidget src/main.js I needed to utilize Requirejs for loading: <script> requirejs.config({ paths: { ...

Exploring the concept of sharing variables between files in Node.js and JavaScript

I have a situation where I am working with files that require database access. One of the files contains code like this: ... var dynamo = new AWS.DynamoDB.DocumentClient(); module.exports.getDatabase= function(){ return dynamo; }; ... I'm curiou ...

What could be causing my script files to not load when I use ajax load() to bring external content into a #content div?

I am currently troubleshooting why my JS files, or script files, are not loading when I bring external content into the #content DIV. While the HTML and CSS load correctly, the scripts do not. Upon page load, my index page, complete with head, body, sc ...

"Unlock the Power of VueJS 2 with Dynamic Templates

Just starting out as a VueJS student! I created a "MainTemplate.vue", which includes a menu, footer, header... Then I decided to create another .vue file named "ComponentB.vue". Here is the content of my ComponentB.vue file: <template> <h ...

Is there a way for me to retrieve the current value of a star rating when I click on it?

Looking for assistance with a ReactJS rating stars component that behaves oddly. The starting value is set to 5 stars, but each click on the stars seems to return the previous value rather than the current one. import React, {useState} from "react&quo ...

Ajax request in Rails not receiving a response from the controller

After troubleshooting a simple GET request to the controller action, I confirmed that the request is being made successfully and there are no issues with the controller executing the action. However, I am not receiving any response data. $.ajax({ url: ...

Contrasting VSCode Live Server and Node Live Server

Recently delving into the world of JS, I've come across the need to set up a live server using npm. One popular extension in VSCode known as Live Server by Ritwick Dey caught my attention. I'm curious about the distinctions between utilizing this ...

Despite having a result, the Promise is returning an undefined value

In Vuejs, I have a method named getUsers that takes an array as input and fetches user data from the database. When calling it like this, it successfully returns the results: this.getUsers(executives).then( result => { this.speci ...

Uncovering the unique properties of custom Items in MUI v5 - RichTreeView: A Step-by-Step Guide

Can custom item properties received asynchronously with MUI - RichTreeView be exposed inside a custom treeItem? For instance, how can the customProperty1 and customProperty2 be accessed within the CustomTreeItem? The console.log to props only shows defaul ...

"Code snippets customized for React are not functioning properly in the javascriptreact.json file within Visual Studio Code

I'm looking to incorporate some customized React.js code snippets into my Visual Studio Code setup. I am aware of the two files in VSCode that handle this - javascript.json and javascriptreact.json. Although the snippets work well in javascript.json, ...

When employing useNavigation, the URL is updated but the component does not render or appear on the

Check out this code snippet: https://codesandbox.io/p/sandbox/hardcore-lake-mptzw3 App.jsx: import ContextProvider from "./provider/contextProvider"; import Routes from "./routes"; function App() { console.log("Inside App" ...

It appears that the JS function is not being triggered

I am facing an issue with my JavaScript code where a ball is not showing up even though it should. I have an array with only one element, and when that element matches with "F2", the ball is supposed to appear. I suspect there might be a problem with my us ...

JavaScript automatically arranges child elements within their parent container in a random distribution without any overlapping

I am experimenting with creating a dynamic layout of circles (divs with border-radius) within a container without any overlap. Check out my progress here - https://jsbin.com/domogivuse/2/edit?html,css,js,output var sizes = [200, 120, 500, 80, 145]; var m ...

When attempting to declare a functional component in React utilizing styled-components in TypeScript, an error is encountered stating "No overload matches this call."

Playground https://codesandbox.io/s/typescript-type-checking-question-0b42t Sample Code type BadgeTypes = { success: string; secondary: string; alert: string; text: string; }; type Theme = { fonts?: object; borderRadius: string; primary?: o ...