Component automagically wrapped with additional v-container when loaded with router-view - vue.js

I'm writing here, because I cannot find the response, or better, I found myself unable to formulate proper question to find it.
My question is:
Given the App.vue structure: (simplified)
<v-main>
<v-container fluid fill-height>
<router-view />
</v-container>
</v-main>
and the Component.vue structure:
<v-row>
<v-col>
Component Content
</v-col>
</v-row>
Why is the rendered component wrapped with the plain <v-container>?:
<main class="v-main" style="padding: 64px 0px 0px;">
<div class="v-main__wrap">
<div class="container container--fluid fill-height"> // App.vue
<div class="container"> // ????
<div class="row"> // component code
<div class="col">
Is it some secret vue-router or vuetify template?
Could anyone explain why this happens and if there is a way to avoid this?
Edit: versions:
Dependencies:
req: inst:
core-js ^3.8.3 3.21.1
vue ^2.6.14 2.6.14
vue-router ^3.5.1 3.5.3
vuetify ^2.6.0 2.6.4
vuex ^3.6.2 3.6.2
Dev dependencies:
req: inst:
#babel/core ^7.12.16 7.17.7
#babel/eslint-parser ^7.12.16 7.17.0
#vue/cli-plugin-babel ~5.0.0 5.0.3
#vue/cli-plugin-eslint ~5.0.0 5.0.3
#vue/cli-plugin-router ~5.0.0 5.0.3
#vue/cli-plugin-vuex ~5.0.0 5.0.3
#vue/cli-service ~5.0.0 5.0.3
eslint ^7.32.0 7.32.0
eslint-plugin-vue ^8.0.3 8.5.0
sass ~1.32.0 1.32.13
sass-loader ^10.0.0 10.2.1
vue-cli-plugin-vuetify ^2.4.7 2.4.7
vue-template-compiler ^2.6.14 2.6.14
vuetify-loader ^1.7.0 1.7.3

Ok, my bad, I didn't realize that it was because the parent component of this particular subview <v-container> wasn't marked as fluid.
All fixed now. Since the parent was only a template with a container and a router-view without any logic, I'd completely forgotten about it.

Related

<v-otp-input> - did you register the component correctly?

im working on a nuxt project and im using vuetify as a UI framework.
i tried using v-otp-input but i get this error in my console.
all the vuetify elements are working fine but this one doesn't , what should i do ?
here is my code
<v-otp-input
:error-messages="codeErrorMsg"
v-model="password"
type="password"
length="5"
dark
></v-otp-input>
ps:im looking for somthing like this:
Any help would be appreciated
that was because of vuetify version (vuetify version must be 2.6.0 or higher)
for updating vuetify:
1.Run npm info vuetify to lookup for the list of versions that they have.
npm info vuetify
2.install the specific version that you want with the following
for example:
npm install --save vuetify#2.6.6
You can use Vuetify <v-opt-input> component and override a bit its css for your needs.
<v-otp-input
length="6"
plain
type="number"
></v-otp-input>
To edit the css style of the component, it's not an easy task as you have to check on the browser debugger what are the classes applied to the component and what elements it includes.
But it's doable :)
Assuming you are using the last Vuetify version (2.6.6) you have to wrap your page or your layout into a component: https://vuetifyjs.com/en/api/v-app/
<template>
<v-app>
<v-otp-input
:error-messages="codeErrorMsg"
v-model="password"
type="password"
length="5"
dark
></v-otp-input>
</v-app>
</template>
I had the same problem, using vuetify v2.6.9, with vue-cli-plugin vuetify. I tried manually importing the component in my component and it worked:
<template>
<v-otp-input
class="
font-weight-bold
text-uppercase
btn-primary
bg-gradient-primary
py-2
px-6
me-2
mt-7
mb-2
w-100
"
color="#5e72e4"
v-model="otp"
:disabled="loading"
#finish="onFinish"
></v-otp-input>
</template>
<script>
import { VOtpInput } from "vuetify/lib";
export default {
name: "sign-up-verify",
components: { VOtpInput },
}
</script>

why my vuejs component does not render, i need a library?

i have this component, its a simple component, but does not render, just i see words "Sales", i need to install another library?
<template>
<v-app>
<v-container>
<v-row dense align="stretch">
<v-col cols="4">
<v-card min-height="100%">
<v-card-text class="green--text">
<h5 class="text-truncate text-uppercase">Sales</h5>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</v-app>
</template>
<script>
export default {
name: 'Taps',
setup() {
},
}
</script>
my dependencies are:
"vue": "^3.2.20",
"vue-router": "^4.0.0-0",
"vue3-perfect-scrollbar": "^1.5.5",
"vuex": "^4.0.0-0",
Unfortunately Vuetify does not yet support Vue 3.
The current version of Vuetify does not support Vue 3. Support for Vue 3 will come with the release of Vuetify v3. When creating a new project, please ensure you selected Vue 2 from the Vue CLI prompts, or that you are installing to an existing Vue 2 project.
You'll need to downgrade your Vue version or choose a different component library. Quasar is a great alternative to Vuetify with lots of the same components and features.

I have an error with otp component in vuetify in vue

I have a problem in vuetify when I want to use OTP input component.
My code is here :
https://vuetifyjs.com/en/components/otp-input/#finish-event
<div class="ma-auto position-relative" style="max-width: 300px">
<v-otp-input
v-model="otp"
:disabled="loading"
#finish="onFinish"
></v-otp-input>
<v-overlay absolute :value="loading">
<v-progress-circular
indeterminate
color="primary"
></v-progress-circular>
</v-overlay>
</div>
My error is :
its because of your vuetify version (vuetify version must be 2.6.0 or higher)
for updating vuetify:
1.Run npm info vuetify to lookup for the list of versions that they have.
npm info vuetify
2.install the specific version that you want with the following
for example:
npm install --save vuetify#2.6.6

how to install vuetify 1.5.18

how to install vuetify version 1.5.18? I followed this method https://github.com/vuetifyjs/vue-cli-plugin-vuetify/issues/99, but in this way I got version 2.0.0. I followed this method how to add old version of vuetify and adding this code into App.vue (this code vuetify version 1.5.18 toolbars):
<template>
<v-toolbar>
<v-toolbar-side-icon></v-toolbar-side-icon>
<v-toolbar-title>Title</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-items class="hidden-sm-and-down">
<v-btn flat>Link One</v-btn>
<v-btn flat>Link Two</v-btn>
<v-btn flat>Link Three</v-btn>
</v-toolbar-items>
</v-toolbar>
</template>
did not happen, there was no vuetify only plain text. What should I do?
Try to use following link to install your required version of vuetify,
https://github.com/vuetifyjs/vuetify/releases/tag/v1.5.18
try npm install vuetify#1.5.8
or in package.json change version of vuetify to 1.5.8 then do npm install
Use: npm i vuetify#1.5.* or specify last point version, ex. npm i vuetify#1.5.18.

Building deeply nested html with vue-cli takes forever

I found that vue-cli (2.9.6, but 3.0.0 beta* has the same issue) 's building process takes forever once the template's html gets relativelly deep.
For example, I just added some divs to App.vue which is pre-included:
<template>
<div id="app">
<img src="./assets/logo.png">
<div><div><div><div></div></div></div></div>
<HelloWorld/>
</div>
</template>
which doesn't take so long.
But once it gets this:
<template>
<div id="app">
<img src="./assets/logo.png">
<div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<HelloWorld/>
</div>
</template>
then the building process takes forever, and I believe that the nest of this depth isn't so uncommon.
How should I deal with this problem?
EDIT(Details)
It seems that the problem might be environment specific, so here are the details.
This problem can be reproduced with these environments at least:
macOS High Sierra on Mac mini (Late 2014)
Ubuntu 18.04 on Dell XPS 13
and node and npm version are:
node --version
# prints
v8.9.4
# and
npm version
# prints
{ npm: '6.1.0',
ares: '1.10.1-DEV',
cldr: '31.0.1',
http_parser: '2.7.0',
icu: '59.1',
modules: '57',
nghttp2: '1.25.0',
node: '8.9.4',
openssl: '1.0.2n',
tz: '2017b',
unicode: '9.0',
uv: '1.15.0',
v8: '6.1.534.50',
zlib: '1.2.11' }
With these, I've retried the followings on my Mac:
npm uninstall -g vue-cli
npm install -g vue-cli
vue init webpack divnest
# then some Enter keys - everything is default
cd divnest
Then, open up App.vue and put many divs:
<template>
<div id="app">
<img src="./assets/logo.png">
<div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<router-view/>
</div>
</template>
(Since I used the default settings here, <router-view/> is included unlike the original post, but should not be the problem.)
And finally,
npm run dev
which takes forever - specifically, the process stops at this point:
13% building modules 28/31 modules 3 active ...myname/Documents/divnest/src/App.vue
In the case of
npm run build
, the process stops at this point:
> divnest#1.0.0 build /Users/myname/Documents/divnest
> node build/build.js
Hash: 483ebabc54d5aed79fd7
Version: webpack 3.12.0
Time: 13742ms
Asset Size Chunks Chunk Names
static/js/vendor.7fed9fa7b7ba482410b7.js 112 kB 0 [emitted] vendor
static/js/app.f1ebca7a6e0ec0b7ebdf.js 12 kB 1 [emitted] app
static/js/manifest.2ae2e69a05c33dfc65f8.js 857 bytes 2 [emitted] manifest
static/css/app.30790115300ab27614ce176899523b62.css 432 bytes 1 [emitted] app
static/css/app.30790115300ab27614ce176899523b62.css.map 828 bytes [emitted]
static/js/vendor.7fed9fa7b7ba482410b7.js.map 553 kB 0 [emitted] vendor
static/js/app.f1ebca7a6e0ec0b7ebdf.js.map 23.3 kB 1 [emitted] app
static/js/manifest.2ae2e69a05c33dfc65f8.js.map 4.97 kB 2 [emitted] manifest
index.html 509 bytes [emitted]
Build complete.
Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won't work.
94% asset optimization
and if I let it go, it takes... 1155409ms!!!!
DONE Compiled successfully in 1155409ms 13:35:34
I Your application is running here: http://localhost:8080
MORE EDIT
As #tony19 pointed out, prettier is the likely suspect. Following the advice, I've tried some patterns with Ubuntu 18.04 (not Mac because Mac isn't here right now, sorry) and my results are:
vue-cli 2.9.6 + npm run dev - hang
vue-cli 2.9.6 + npm run build - 6 secs (This is so confusing. What was the 1 million seconds above!? Maybe reinstalling vue-cli owes the change?)
vue-cli 3.0.0-beta16 + vue serve - hang (as opposed to #tony19's report)
vue-cli 3.0.0-beta16 + vue build - 5 secs
EVEN MORE EDIT
So, it seems that this is definitely caused by prettier.
https://github.com/prettier/prettier/issues/1250
is the original issue that addressed this problem and the dev team thought that https://github.com/prettier/prettier/pull/2259 fixed it, but the reality is that it couldn't handle my case, as #tony19 shows it on https://github.com/prettier/prettier/issues/4672 . Oh well.
"SOLUTION"
I ended up doing this - following #tony19's report, changing /node_modules/vue-loader/lib/template-compiler/index.js lines 78:81
if (!isProduction) {
code = prettier.format(code, { semi: false })
}
to
// if (!isProduction) {
// code = prettier.format(code, { semi: false })
// }
thus the problem is solved. Thank you frontend, thank you.
I can reproduce the performance issue as you described (macOS High Sierra 10.13.4, Node 8.9.4 and 9.11.1). The issue also occurs with a newly created vue-cli 3.x project.
The hang is actually happening in prettier, called from vue-loader's template compiler. The nested <div>s are converted into JavaScript by vue-loader, and that becomes the following snippet:
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{attrs:{"id":"app"}},[_c('img',{attrs:{"src":require("./assets/logo.png")}}),_vm._v(" "),_c('router-view'),_vm._v(" "),_vm._m(0)],1)}
var staticRenderFns = [function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div',[_c('div')])])])])])])])])])])])])])])])])])])])])])])])])}]
vue-loader passes this long string to prettier, which takes about 159 seconds to process. The cause of the bug is the deeply nested function calls that create the divs. I've reported this bug in prettier (Issue 4672).
In the meantime, I recommend refactoring your HTML to avoid deep nesting. If you need to stick with the old template, you could workaround the issue by building in production mode, as vue-loader skips prettier for production builds:
NODE_ENV=production npm run dev
UPDATE vue-loader v15.5.0 adds the prettify option to allow disabling prettier (update to the latest version of #vue/cli to ensure your vue-loader is current with the new option). You can use this option as follows:
Add vue.config.js (if it doesn't exist already) to the root of your project.
Edit the file to include:
module.exports = {
chainWebpack: config => {
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.prettify = false
return options
})
}
}
Update 2019
Recently vue-loader added a flag in their options in order to disable prettier also during development.
Just add prettify: false to your vue-loader options.
https://vue-loader.vuejs.org/options.html#prettify
Notice: Just make sure you have the latest vue-loader version
I had similar issues with vue-cli 3.1.1 (TypeScript + SCSS) and Bootstrap (which by default requires some nesting). Example structure:
<template>
<div class="container">
<div class="row">
<div class="col-12">
<div class="card-deck">
<div class="card">
<div class="card-body">
<div class="accordion">
<div class="card">
<div class="card-header">
...
</div>
<div class="collapse">
<div class="card-body">
<div class="row">
<div class="col-12 form-group">
<label>...</label>
<div class="dropdown">
<button class="custom-select" type="button" data-toggle="dropdown">{{someValue}}</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" :data-key="somekey1" #click="onClickMethod">value1</a>
<a class="dropdown-item" href="#" :data-key="somekey2" #click="onClickMethod">value2</a>
...
needed ~12 seconds to compile 400+ lines of code (template + TypeScript + SCSS). After removing:
:data-key="somekey1" #click="onClickMethod"
:data-key="somekey2" #click="onClickMethod"
the code needed ~5-6 seconds to compile. After moving the code to custom component (and some TypeScript code from Vue component to Helper.ts file):
<template>
<div class="container">
<div class="row">
<div class="col-12">
<div class="card-deck">
<div class="card">
<div class="card-body">
<div class="accordion">
<div class="card">
<div class="card-header">
...
</div>
<div class="collapse">
<div class="card-body">
<SubComponent/>
it needs ~700ms to compile (one main component and two additional sub-components, each file having less than 100 lines of code + Helper.ts having exactly 97 lines of code).
So if you suffer from poor npm run serve performance, try sub-components first, I didn't noticed much difference in compile time while invoking npm run build so I assume (maybe incorrectly) that this problem is also caused by code prettifier which is enabled for serve but disabled for build (TSLint is not invoked on save action so it does not affect npm run serve in my case).
I do not have any particular issue with your 25 nested <div>'s: (below example with Vue runtime compiler, so that you can easily test it directly in your browser)
new Vue({
el: '#app',
template: '#app-template',
});
#app div {
border: 1px solid grey;
padding: 1px;
}
<script src="https://unpkg.com/vue#2"></script>
<div id="app">
</div>
<template id="app-template">
<div id="app">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>25 nested <code><div></code>'s</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
Here is a demo with a Vue CLI project on CodeSandbox, probably closer to your example: https://codesandbox.io/s/v3knpl447l
(i.e. it precompiles the templates, so the building process actually happens on CodeSandbox server)