Trying to create a navigation bar that exists across my Vue application. Coming from react so I'm trying to do import my Navigation Component into main.ts and use it above the router outlet in App.vue. Application was generated using vue-cli with typescript and Router.
I've tried writing the navigation component with Vue.extend
, @Component
, export default {*/ options */}
.
I've tried adding a script tag in App.vue inside of which I would register Navigation component.
I've import and registered the Navigation component in main.ts.
Navigation.ts:
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
import { store } from '@/store';
@Component({
name: 'nav-component',
})
export default class Navigation extends Vue {}
Navigation.vue:
<template>
<nav class="nav-header" >
<div>
<button class="switch-map">MAP</button>
</div>
</nav>
</template>
<script src='./Navigation.component.ts' ></script>
<style lang="scss" scoped src='./Navigation.scss' ></style>
main.ts:
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
// various imports
import NavigationComponent from
'@/components/Navigation/Navigation.component';
Vue.config.productionTip = false;
new Vue({
components: {
'nav-component': NavigationComponent
},
data: {
},
store: store,
router,
render: h => h(App)
}).$mount("#app");
App.vue:
<template>
<div id="app">
<nav-component></nav-component>
<router-view/>
</div>
</template>
Expected: navigation bar across top of application throughout all pages (i only have two routes at the moment)
Actual: unknown custom element ''. Did you register it correctly? For recursive components be sure to include the 'name' option.
A lot of alternatives have just led to the 'Failed to mount component: template or render function not defined' error message. Any suggestions out there? Thanks for any help!