質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

Q&A

解決済

1回答

1408閲覧

Nuxt.jsのlayoutsに制限をかけたい。

toshihirokato

総合スコア20

Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

0グッド

0クリップ

投稿2020/01/23 04:44

前提・実現したいこと

現在、Nuxtjs+Vuetifyを使ってwebアプリを開発しています。

そこで、UIを統一するためにNuxt.jsのlayoutsディレクトリを使用しているのですが、
1ページだけ、layoutsディレクトリに指定したUiを指定せずに描画されるようにしたいです。

発生している問題

layouts/default.vue を、あるページだけ表示されないようにしたい。

該当のソースコード

components

1<template> 2 <v-app id="inspire"> 3 <v-navigation-drawer 4 v-model="drawer" 5 app 6 clipped 7 > 8 <v-list dense> 9 <v-list-item 10 v-for="item in items" 11 :key="item.text" 12 link 13 > 14 <v-list-item-action> 15 <v-icon>{{ item.icon }}</v-icon> 16 </v-list-item-action> 17 <v-list-item-content> 18 <v-list-item-title> 19 {{ item.text }} 20 </v-list-item-title> 21 </v-list-item-content> 22 </v-list-item> 23 <v-subheader class="mt-4 grey--text text--darken-1"> 24 SUBSCRIPTIONS 25 </v-subheader> 26 <v-list> 27 <v-list-item 28 v-for="item in items2" 29 :key="item.text" 30 link 31 > 32 <v-list-item-avatar> 33 <img 34 :src="`https://randomuser.me/api/portraits/men/${item.picture}.jpg`" 35 alt="" 36 > 37 </v-list-item-avatar> 38 <v-list-item-title v-text="item.text" /> 39 </v-list-item> 40 </v-list> 41 <v-list-item 42 class="mt-4" 43 link 44 > 45 <v-list-item-action> 46 <v-icon color="grey darken-1"> 47 mdi-plus-circle-outline 48 </v-icon> 49 </v-list-item-action> 50 <v-list-item-title class="grey--text text--darken-1"> 51 Browse Channels 52 </v-list-item-title> 53 </v-list-item> 54 <v-list-item link> 55 <v-list-item-action> 56 <v-icon color="grey darken-1"> 57 mdi-settings 58 </v-icon> 59 </v-list-item-action> 60 <v-list-item-title class="grey--text text--darken-1"> 61 Manage Subscriptions 62 </v-list-item-title> 63 </v-list-item> 64 </v-list> 65 </v-navigation-drawer> 66 67 <v-app-bar 68 app 69 clipped-left 70 color="rgba(255, 204, 0, 1)" 71 dense 72 > 73 <v-app-bar-nav-icon @click.stop="drawer = !drawer" /> 74 <v-toolbar-title class="mr-12 align-center"> 75 <span class="title">Google contacts</span> 76 </v-toolbar-title> 77 <v-spacer /> 78 <v-row 79 align="center" 80 style="max-width: 650px" 81 > 82 <v-text-field 83 :append-icon-cb="() => {}" 84 placeholder="Search..." 85 single-line 86 append-icon="search" 87 color="#1A237E" 88 hide-details 89 /> 90 </v-row> 91 </v-app-bar> 92 93 <v-content> 94 <v-container class="fill-height"> 95 <v-row 96 justify="center" 97 align="center" 98 /> 99 </v-container> 100 </v-content> 101 </v-app> 102</template> 103 104<script> 105export default { 106 props: { 107 // eslint-disable-next-line 108 source: String 109 }, 110 data: () => ({ 111 drawer: null, 112 items: [ 113 { icon: 'mdi-trending-up', text: 'Most Popular' }, 114 { icon: 'mdi-youtube-subscription', text: 'Subscriptions' }, 115 { icon: 'mdi-history', text: 'History' }, 116 { icon: 'mdi-playlist-check', text: 'Playlists' }, 117 { icon: 'mdi-clock', text: 'Watch Later' } 118 ], 119 items2: [ 120 { picture: 28, text: 'Joseph' }, 121 { picture: 38, text: 'Apple' }, 122 { picture: 48, text: 'Xbox Ahoy' }, 123 { picture: 58, text: 'Nokia' }, 124 { picture: 78, text: 'MKBHD' } 125 ] 126 }), 127 created () { 128 this.$vuetify.theme.dark = false 129 } 130} 131</script> 132 133<style> 134.title { 135 color: #1A237E; 136} 137</style> 138

layouts

1<template> 2 <div> 3 <TheHeader /> 4 <div class="wrapper"> 5 <nuxt class="container" /> 6 </div> 7 </div> 8</template> 9 10<script> 11import TheHeader from '~/components/TheHeader.vue' 12 13export default { 14 components: { 15 TheHeader 16 } 17} 18</script> 19

❗️このファイルだけ表示されたくない❗️

pages

1<template> 2 <v-app id="inspire"> 3 <v-content> 4 <v-container 5 class="fill-height" 6 fluid 7 > 8 <v-row 9 align="center" 10 justify="center" 11 > 12 <!-- cols="columns" --> 13 <v-col 14 cols="12" 15 xl="14" 16 md="8" 17 > 18 <v-card class="elevation-12"> 19 <v-toolbar 20 color="primary" 21 dark 22 flat 23 > 24 <v-toolbar-title>Login form</v-toolbar-title> 25 <v-spacer /> 26 </v-toolbar> 27 <v-card-text> 28 <v-form> 29 <v-text-field 30 label="Login" 31 name="login" 32 prepend-icon="person" 33 type="text" 34 /> 35 36 <v-text-field 37 id="password" 38 label="Password" 39 name="password" 40 prepend-icon="lock" 41 type="password" 42 /> 43 </v-form> 44 </v-card-text> 45 <v-card-actions> 46 <v-spacer /> 47 <v-btn color="primary"> 48 Login 49 </v-btn> 50 </v-card-actions> 51 </v-card> 52 </v-col> 53 </v-row> 54 </v-container> 55 </v-content> 56 </v-app> 57</template> 58 59<script> 60export default { 61 props: { 62 // eslint-disable-next-line 63 source: String 64 } 65} 66</script> 67

試したこと

nuxt.jsのlayoutsがとても便利
Nuxt.js公式ドキュメント

上記の記事を参考に、pagesディレクトリに存在するファイルのscriptタグ内に
layout: "" または、layout: false を追記したが、解決しませんでした。

補足情報(FW/ツールのバージョンなど)

packagejson

1{ 2 "name": "", 3 "version": "1.0.0", 4 "description": "My epic Nuxt.js project", 5 "author": "", 6 "private": true, 7 "scripts": { 8 "dev": "nuxt", 9 "build": "nuxt build", 10 "start": "nuxt start", 11 "generate": "nuxt generate", 12 "lint": "eslint --ext .js,.vue --ignore-path .gitignore ." 13 }, 14 "dependencies": { 15 "@nuxtjs/axios": "^5.9.3", 16 "analyze": "^0.0.14", 17 "chart.js": "^2.9.3", 18 "config": "^3.2.5", 19 "cryptiles": "^4.1.3", 20 "eslint-plugin-import": "^2.20.0", 21 "eslint-plugin-vue": "^6.1.2", 22 "eslint-scope": "^5.0.0", 23 "firebase": "^7.7.0", 24 "hard-source-webpack-plugin": "^0.13.1", 25 "hoek": "^6.1.3", 26 "latest": "^0.2.0", 27 "material-design-icons-iconfont": "^5.0.1", 28 "nuxt": "^2.11.0", 29 "stylus": "^0.54.7", 30 "stylus-loader": "^3.0.2", 31 "tunnel-agent": "^0.6.0", 32 "underscore.string": "^3.3.5", 33 "vue-chartjs": "^3.5.0", 34 "webpack": "^4.41.5", 35 "yarn": "^1.21.1" 36 }, 37 "devDependencies": { 38 "@nuxtjs/eslint-config": "^2.0.0", 39 "@nuxtjs/eslint-module": "^1.1.0", 40 "@nuxtjs/vuetify": "^1.10.2", 41 "babel-eslint": "^10.0.3", 42 "eslint": "^6.8.0", 43 "eslint-plugin-nuxt": ">=0.5.0" 44 } 45}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

###解決方法

カスタムレイアウトを使ってトップページだけヘッダーを表示しないようにする

こちらの記事を参考に、layoutsディレクトリにちがうヘッダーを適当に作成し、
layout: 'sample'と指定したところ無事解決いたしました。

投稿2020/01/28 05:35

toshihirokato

総合スコア20

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問