Vue.js

How to show a different html element/tag based on supplied prop in VueJs

我与影子孤独终老i 提交于 2021-01-29 15:18:39
问题 In Vuejs a <template> can only contain one root element, but what to do if you want to render different html element based on a prop? For example, I have a <heading> component which I want to show/render <h1> if title prop, prop: {title: {type: String, required: true}} is title , and show/render <h3> if it is subtitle And that reminds me, what if I want to do this for all h tags ? I mean based on prop condition, show one of these <h1> to <h6> ? 回答1: The is attribute will allow you to

Vuetify data table - manually display expandable rows

回眸只為那壹抹淺笑 提交于 2021-01-29 15:10:36
问题 I have a bunch of dynamic columns in a v-data table which I need to loop through and interrogate in order to display the correct info. It looks a bit like this (taken from the answer here: Vuetify format cell based on item type) <v-data-table :item="items" ... > <template v-for="header in headers" v-slot:[`item.${header.value}`]="{ item } "> <template v-if="header.type === 'foo'"> <span style="color: red;">{{ item[header.value] }}</span> </template> <template v-else-if="header.value === 'data

Vuetify css not applying in Heroku

人盡茶涼 提交于 2021-01-29 14:59:08
问题 I'm developing a rails app, that uses vue through webpacker. Inside of the vue app I import vuetify and vuetify.css like so: import Vue from 'vue' import Vuetify from 'vuetify' import VueRouter from 'vue-router' import 'vuetify/dist/vuetify.min.css' import App from '../app.vue' import Axios from 'axios' import VueAxios from 'vue-axios' import Vuex from 'vuex' Works fine locally, but when pushed to heroku it no longer works. The app deploys, and it appears like vuetify is included, but the

Tabulator + Nuxt.js: How to use axios in callbacks?

风流意气都作罢 提交于 2021-01-29 14:46:47
问题 I try to add Tabulator in my Nuxt.js project. I have done the next component: <template> <div ref="table"></div> </template> <script> let Tabulator = require("tabulator-tables") import 'tabulator-tables/dist/css/tabulator_simple.min.css' let saveIcon = function(cell, formatterParams, onRendered) { return "<img src='/icons/save.png'>"; } export default { data() { return { tabulator: null, tableData: [ { id: 1, username: 'user', email: 'email@email.ru', activationCode:'1243412-123413-4134',

vue.js array into Django

折月煮酒 提交于 2021-01-29 14:42:09
问题 So I want to go through my array which ive crated on vue.js and then check against the arrary to decide where to save it. To explain it a bit more here's the code i have so far Vue.js var app= new Vue({ el: '.con', data:{ posts: [ { title:'', content:'', type:'' } ], }, methods:{ addHead(index){ this.posts.push({ content:'', type:'header', }) }, addPara(index){ this.posts.push({ content:'', type:'para', }) }, removeForm(){ this.posts.splice(index, 1) } } }) HTML <div class="con"> <button type

TypeError ERR_UNESCAPED_CHARACTERS on testing Vue project using Nightwatch

邮差的信 提交于 2021-01-29 14:18:07
问题 I have a problem trying to setup my Nightwatch environment with Vue CLI. At this point, I just want to make it work with Chrome (we'll see for Firefox soon) but when I run a simple test, It doesn't work. Here is my test file: module.exports = { 'default e2e tests': browser => { browser .url("http://localhost:8080") .waitForElementVisible('#app', 5000) .assert.ok(true) .end() } } throwing the folowing error: Error while running .isElementDisplayed() protocol action: TypeError [ERR_UNESCAPED

Why doesn't jest.spyOn() sometimes work on a Vue component's method?

独自空忆成欢 提交于 2021-01-29 14:18:02
问题 I see the changes the method makes as event handler, but jest.spyOn(wrapper.vm, 'methodName') doesn't catch the call in major cases, but in some tests it somehow works. I suspect a possible re-render (maybe, due to options argument in mount() call), that replaces the original method with the jest.spyOn() , because, if I trigger event twice in a row, toHaveBeenCalled() fulfills and tracks the call. The component: <template> <v-app-bar app color="primary" dark class="header" > <router-link :to=

Is anonymous function in Vue Template a performance killer?

蓝咒 提交于 2021-01-29 13:53:49
问题 I have following setup: In Child component: <template> <div @click="clickHandler"> </div> </template> <script> ... clickHandler() { this.$emit('emittedFunction', someInfo, otherInfo) } </script> In Parent component: <template> <child-component v-for="index in 10" @emittedFunction="(someInfo, otherInfo) => someFunction(index, someInfo, otherInfo)"/> </template> <script> ... someFunction(index, someInfo, otherInfo) { do stuff } </script> This code works perfectly fine. To my question though: A

Vue computed property in router template

元气小坏坏 提交于 2021-01-29 13:52:44
问题 I'm having trouble understanding how to get a computed property all the way out through the router to my template. Here's a basic idea of what I'm doing: const Home = { template: '<router-link to="/level/1">Level 1</router-link>' } const Level = { template: '<template>|{{ id }}|{{ message }}|</template>', props: ['id','message'] } const router = new VueRouter({ routes: [ { path: '/', component: Home, props: true }, { path: '/level/:id', component: Level, props: true } ] }) const vm = new Vue(

Cannot import bootstrap in nuxt vue component [duplicate]

爱⌒轻易说出口 提交于 2021-01-29 13:27:49
问题 This question already has answers here : “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6 (12 answers) Closed 10 months ago . I can't import bootstrap in any vue component (using latest nuxtjs). I get : My (simple) component is : <template> <h1>Empty index page</h1> </template> <script> import Modal from 'bootstrap/js/src/modal' export default {} </script> <style></style> I am really stuck. Do you have any idea or suggestion ? 回答1: You should