What is the best way to implement a custom layout with nuxt-property-decorator?

Summary of Different Header Components in Nuxt

In order to set a different header component for a specific page in Nuxt, you can create separate layout files.

layout
  ├ default.vue // <- common header
  └ custom.vue // <- special header for specific page

If you want to know how to set different layouts using nuxt-property-decorator, refer to the documentation here.

"nuxt": "^2.15.7",
"nuxt-property-decorator": "^2.9.1",

Code Examples

Case 1

<script lang="ts">
import { Component, Vue,} from 'nuxt-property-decorator'

@Component
export default class CustomComponent extends Vue {
  layout () { // <- error on layout
    return 'custom'
  }
}

The above code returns an error:

Duplicate function implementation.Vetur(2393)

Case 2

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'

@Component({
  layout: 'custom' // <- error on layout: 'custom'
})
export default class CustomComponent extends Vue {
}

The above code returns an error:

No overload matches this call.
  Overload 1 of 2, '(options: ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<DefaultProps>, DefaultProps> & ThisType<...>): <VC extends VueClass<...>>(target: VC) => VC', gave the following error.
    Argument of type '{ layout: string; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<DefaultProps>, DefaultProps> & ThisType<...>'.
      Object literal may only specify known properties, and 'layout' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<DefaultProps>, DefaultProps> & ThisType<...>'.
  Overload 2 of 2, '(target: VueClass<Vue>): VueClass<Vue>', gave the following error.
    Argument of type '{ layout: string; }' is not assignable to parameter of type 'VueClass<Vue>'.
      Object literal may only specify known properties, and 'layout' does not exist in type 'VueClass<Vue>'.Vetur(2769)

Answer №1

After some investigation, I discovered that setting the layout on pages is essential, rather than on components.

├ components
│  └ index.vue // <- make sure it's not set here
└ pages 
   └ index.vue // <- set it here

Success was achieved by setting the layout in pages/index.vue:

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'

@Component({
  layout: 'custom',
})
export default class Page extends Vue {

}
</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

Issues arise when trying to use additional loaders with Storybook 6.x and Vue 2

Moving over to Storybook 6.4 I am working on a story that involves loading a Vue component, but I keep encountering errors: ModuleParseError: Module parse failed: Unexpected token (92:0) File was processed with these loaders: * ./node_modules/vue-docgen- ...

Explaining the union type using a list of data types

Is there a way to create a union type that strictly limits values to 'a', 'b', 'c' when using a list like const list: string[] = ['a', 'b', 'c']? I know one method is: const list = ['a' ...

`The steps to retrieve XML response data from an API request`

When using axios to make an API request, how can I receive data in XML format? For example: axios.get(/* URL */).then(response => {/* How do I retrieve the XML data? */}).catch(err => {/* result */}); ...

Is there a way for me to access the current templating in AngularJS?

I am looking to retrieve the HTML page as a string after AngularJS has finished rendering the template. My goal is to send this content to the server. .controller('MyCtrl', ['$scope', '$location', function ( $scope, $location ...

How does express.route determine the route?

I have recently started learning about Node.js (specifically with Express.js) and React.js. As a result, I have some questions regarding Express Router. Let me share a portion of my code with you: server.js const app = express(); const apiRouter = requi ...

The final thumbnail fails to appear in the visible display (react-responsive-carousel)

I am currently facing an issue with displaying a series of images using react-responsive-carousel. When the images exceed a certain size causing the thumbnail section to become scrollable, the last thumbnail is always out of view. Although I have impleme ...

using node and express to route and pass variables to a required module

In my primary index.js file, I have the following code: var express = require('express') require("dotenv").config(); const db = require('./services/db_service').db_connection() const customers = require('./routes/custo ...

Which specific event in NextJS is triggered only during the initial load?

I am working on a NextJS app and I want to implement an initial loading screen that only appears during the first load. Currently, the loading screen pops up not only on the initial load but also whenever a link is clicked that directs the user back to the ...

What are the steps for including and excluding components in Parallax JS?

When working with Parallax JS: I am trying to modify the components within the <li> tags of my menu, but I am unsure how to do so without restarting the plugin. I cannot seem to find the destroy command. Currently, I am using the JQuery version of ...

What steps should I follow to perform unit testing on a Quasar application with Jest?

I am currently working on a Quasar application that was created using the quasar-cli. I'm trying to figure out how to incorporate unit testing with a test runner like Jest for this type of application. In my Jest configuration, I included the follow ...

Verify if two items possess identical property values

There are 2 items: 1. obj1 = { bookRetail: 14.99, hierarchyDescription: "GUYS DENIM PANTS [ 0151 ]", isSelected: true, isAvailableInPivot: "Y", style: "VICE NWH NAVY WHITE DC [ M450MBON ]"} 2. obj2 = { bookRetail: 14.99, hier ...

Explain the object type that is returned when a function accepts either an array of object keys or an object filled with string values

I've written a function called getParameters that can take either an array of parameter names or an object as input. The purpose of this function is to fetch parameter values based on the provided parameter names and return them in a key-value object ...

Tips for retrieving the option text value following an onchange event in AngularJS

Whenever I change the selection in my dropdown menu for 'Cities', the alert is displaying the value of the previous selection instead of the current one. For example, if I select a state and then switch to Cities, the alert shows the text related ...

Hidden content from Vue router view

My goal is to have the navigation pane overlaying the content of the page, but instead, it is being appended to the bottom where the end of the navigation drawer would be. I've experimented with different variations to display data using navigation dr ...

PhoneGap Troubleshooting: Device Plugin Malfunctioning

I'm having trouble getting the device plugin to work with my Cordova/PhoneGap project. Currently, I am using Cordova version 3.3.1-0.1.2. I followed the documentation and installed the plugin using the following command: C:\ProjectFolder>pl ...

Unable to perform a fetch request in IE9 after the page has finished loading

I'm currently encountering an issue with my Node and Express server setup. I have a separate API on a different server that needs to be accessed, but everything works fine except in IE9. The problem arises when I try to make a call to the API after lo ...

Having trouble retrieving data in Next.js and passing it to client components. It's just not functioning as expected

After asynchronously fetching data, I am passing it to a client component as props. However, the state of the client component is not being properly set and displayed. The props are passing correctly, but the state seems to not update for some reason. Ser ...

Encountering issues while trying to establish a connection to MongoDB through JavaScript

I have developed a code for seamlessly integrating various social networking logins with nodejs. Below is my server.js file: // include the necessary tools var express = require('express'); var app = express(); var port = process.env ...

How can I relocate an object to a different position within THREE.JS?

I'm trying to figure out how to move one object to the position of another object. I found some suggestions online to use the TWEEN library, but I'm having trouble integrating it into my code. Any help would be greatly appreciated :) <scrip ...

My Tailwind CSS toggle button disappears in dark mode, why is that happening?

<button aria-label="Toggle Dark Mode" type="button" className="lg:inline-flex lg:w-40 md:w-screen p-3 h-12 w-12 order-2 md:order-3" onClick={() => setTheme(theme === 'dark' ? &ap ...