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

Opt for JavaScript DOM manipulation over jQuery for element selection without depending on jQuery

I am attempting to target a specific element using JavaScript: element = '<div class="c-element js-element">Something Here</div>'; When I try to select this element with the following code: $(element) The result is not as expected ...

Is it possible for jQuery to execute in a sequential manner?

Below is the code I am working with: https://jsfiddle.net/c4zquo60/1/ CSS: #bg { background-repeat: no-repeat; position: absolute; top:0; bottom:0; left:0; right:0; width:100wh; height:100vh; z-index: -1; opacity: ...

The rationale behind organizing analogous variables into groups

Currently, I am grappling with determining the optimal logic for grouping parameters within a specified tolerance level. Let me illustrate this with an example... Task1: parameter1=140 Task2: parameter1=137 Task3: parameter1=142 Task4: parameter1=139 Task ...

Vue Validator will trigger only after a change event, blur event, or form submission

I am new to using Vue and trying out Vue Validator for the first time. Below is a snippet of my code: <label for="first_name">First name: <span v-if="$validation1.first_name.required" class="invalid">Please enter your first name.</span ...

In JavaScript, JSON data is parsed using a comma separator

Here is the format of my data: [{"QualID":1,"Qualification":"Van Driver"},{"QualID":3,"Qualification":"Safety Cert"},{"QualID":4,"Qualification":"Welder"}] I am look ...

Assigning various variables with a single click of a button

I am attempting to perform multiple actions within a button click event using the Vuetify framework: <v-btn flat color="indigo darken-3" @click.stop="dialogDelete = true; deleteTemporaryId = offer.id">Delete</v-btn> However, it appears that ...

Loading elements of a webpage in a consecutive order

I am currently working on implementing a content slider within my Django application. The specific slider that I am using can be found at this link. One challenge that I am facing is the need to load close to one hundred 'contentDiv' pages, and I ...

Issue in TypeScript where object properties may still be considered undefined even after verifying using Object.values() for undefined values

I'm encountering an issue with TypeScript regarding my interface MentionItem. Both the id and value properties are supposed to be strings, but TypeScript is flagging them as possibly string | undefined. Interestingly, manually checking that id and va ...

How to add a service to a static function in Angular

After incorporating a logger service into my project, I have encountered an issue with using it in NGXS static selectors. The selectors in NGXS are static methods, which prevent me from accessing the logger service injected via Angular DI. Are there any e ...

Tips for Developing Drag Attribute Directive in Angular 2.0

Currently, I am referencing the Angular documentation to create an attribute directive for drag functionality. However, it seems that the ondrag event is not functioning as expected. Interestingly, the mouseenter and mouseleave events are working fine ac ...

How do I retrieve two input values using script code in Ajax?

Currently, I am facing a challenge with implementing two input values in my database search using AJAX. While the script code works well for one input value, it performs poorly with two input values. Below, you will find the codes that I have used. Firstly ...

Encountering a TypeError with Arg 1 while trying to execute the save method in jsPDF

I am currently working on a react project with a simple implementation of jsPDF. I am trying to execute the sample 'hello world' code but encountering an error when using the save method: https://i.stack.imgur.com/o4FWh.png My code is straightf ...

When the user presses either the refresh button or the back button, they will be redirected

After the user presses refresh or uses the browser back button, I need to redirect them to a specific page in order to restart the application. My JavaScript code is as follows: var workIsDone = false; window.onbeforeunload = confirmBrowseAway; function ...

What is the best way to fill an array within an object using React Hooks?

I am encountering an issue with an object that includes an array. Here is the code snippet in question: const [data, setData] = useState({ jobs: [] }); Currently, I am retrieving data from an API and need to append this fetched information to the jobs arr ...

Angular 2: Emptying input field value on click event

I am experiencing an issue with resetting my input values. I have a search bar with filter functions. When I enter a value, it displays a list below and I want to add a function to these links. When I click on one of them, it takes me to another component ...

What could be preventing the background image from displaying properly?

I had the idea to create a game where players have to flip cards to reveal what's on the back, but I'm struggling to get the background image to display properly. As a newcomer to Vue, I'm not sure if I made a mistake somewhere. My intuition ...

Unable to dismiss message in Django

I'm a beginner in Django and I recently followed a tutorial to add message alerts to my code. The alerts are displaying correctly, but unfortunately, I am having trouble closing them using the 'x' button. https://i.stack.imgur.com/BQS1S.png ...

Sending information from Ajax to PHP

Could anyone please explain the script provided above to me? I am attempting to pass the value of $user data so that I can utilize $_REQUEST['user'] within sort.php, but I am encountering difficulties. It seems to be passing in a long URL. $(fun ...

Updating Rails Partial with JSON Data

Updating a partial by appending fetched Facebook posts using the koala gem requires some code adjustments. Here is an example of how to achieve this: # feed_controller.rb def index end def fb_feed @fb_feed = .. respond_to do |format| format.js { ...

When using ReactJS, hovering over a row in a table should trigger a change in the background color of the corresponding row in another table with the same index

I need to create a feature where hovering over a row in the first table will highlight a corresponding row in the second table. The highlighting should be based on the index of the hovered row. Here is an example: <div> <table> < ...