Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

register Single File Components globally

I'm going straight to the point here, I'm creating a registration form using VUEJS. However, when I try to register the component globally it gives me error. Please bear with me I'm still new to vuejs.

when I check the console it gives me this error:

n is not a function

Thanks in advance for the help.

here's my code:

index.php file

<section id="app" class="homepage">
   <div class="content">
    <?php
        $this->load->view($content);
    ?>
   </div>
</section>

<script src="<?php echo base_url(); ?>/js/vue.min.js" ></script>
<script src="<?php echo base_url(); ?>/js/vue-resource.min.js" ></script>
<script src="<?php echo base_url(); ?>/js/app.js" ></script>

app.js file

Vue.component("tour-form", './components/tourForm.vue');

const app =  new Vue({
    el:'#app',
    data(){
        return{
        }
    }
});

tour_form.php file

<tour-form></tour-form>
like image 438
Sam Teng Wong Avatar asked Mar 14 '18 06:03

Sam Teng Wong


People also ask

How do I register for Vue component globally?

When we want to globally register a component in Vue, we need to do it in this file. All you have to do is import your component, as you usually would, and then register it using app. component . import { createApp } from 'vue' import App from './App.

How do I register a component on vue3?

import Vue from "vue";import PopupWindow from "./components/PopupWindow";import App from "./App. vue";Vue. component("PopupWindow", PopupWindow); // global registration - can be used anywherenew Vue({ render: (h) => h(App),}). $mount("#app");

What is single file components?

Single File Components(SFCs) are a style of application organization used by JavaScript UI libraries where each file represents a single component in all aspects. Typically they resemble an HTML document where you have HTML tags, Style Tag, and Script Tag all in a file.

What is global registration and how does it work?

Global registration prevents build systems from removing unused components (a.k.a "tree-shaking"). If you globally register a component but end up not using it anywhere in your app, it will still be included in the final bundle. Global registration makes dependency relationships less explicit in large applications.

What is a single file component?

Single file components are similar to regular components, but there are a few key differences which can make single file components the better tool for your project: They can be defined locally, instead of globally.

How do I register a component globally in Vue?

According to the official documentation, here's how we register a component globally in main.ts file if you're developing using Typescript else in main.js file: import { createApp } from 'vue'; import ComponentC from './components/ComponentC.vue'; // Usually it is App.vue inside the createApp function.

How to register a DLL file as a system global?

These commands are included in the development kit when Visual Basic or Visual FoxPro is installed. Depending on the application, you may have to register several OCX files this way. To register a DLL as a system global, go to the SYSTEM32 directory and locate the DLL mentioned in the error message.


1 Answers

Vue.component() takes the component options ( an object {} ) as its 2nd argument

But you are passing the path of the vue component as a string.

Since you are using .vue files you mivht be using vue-loader to parse these files.

vue-loader transforms the component into a plain javascript module.

So import the component and pass it as the second argument

import TourForm from './components/tourForm.vue'

Vue.component("tour-form", TourForm);

const app =  new Vue({
    el:'#app',
    data(){
        return{
        }
    }
});
like image 160
Vamsi Krishna Avatar answered Oct 19 '22 11:10

Vamsi Krishna