vue-component

Is it possible to emit from mounted in Vuejs?

北城余情 提交于 2019-12-02 20:51:30
问题 I am familiar with emitting data via bus on events and these work great but now I want to emit something but I don't have an event to tie it to. I've tried to emit it on mounted but that hasn't worked as below: mounted(){ bus.$emit('send-test', this.test); }, 回答1: When you add an event handler in the parent's mounted lifecycle event for an event that is emitted in a child's mounted event, the handler will not catch the event emitted by the child because the handler is added after the child

How to write test that mocks the $route object in vue components

给你一囗甜甜゛ 提交于 2019-12-02 18:07:27
I have a component that contains statement like this.$route.fullPath , how should I mock value of fullPath of $route object if I want to test that component? Best not mock vue-router but rather use it to render the component, that way you get a proper working router. Example: import Vue from 'vue' import VueRouter from 'vue-router' import totest from 'src/components/totest' describe('totest.vue', () => { it('should totest renders stuff', done => { Vue.use(VueRouter) const router = new VueRouter({routes: [ {path: '/totest/:id', name: 'totest', component: totest}, {path: '/wherever', name:

Vue.js loading single-file components

落花浮王杯 提交于 2019-12-02 17:37:48
I'm new to Vue.js and want to use single-file components, but I don't understand the workflow. For example, I have three components: App , Grid and List App.vue <template> <div id="app"> <div id="grid"></div> <div id="right"></div> </div> </template> <script> export default { name: 'app', data () { return { message: 'Hello Vue!' } } } </script> Grid.vue <template> <div id="left"></div> </template> <script> export default { name: 'grid', data: function () { return { grid: 'some-data' } } } </script> List.vue <template> <div id="right"></div> </template> <script> export default { name: 'list',

How to share data between components in VueJS

眉间皱痕 提交于 2019-12-02 17:33:03
I have a fairly simple VueJS app, 3 components (Login, SelectSomething, DoStuff) Login component is just a form for user and pass input while the second component needs to display some data obtained in the login progress. How can I share data from one component to the others? So that when I route to second component I still have the data obtained in the Login one? You can either use props or an event bus, where you'll be able to emit an event from a component and listen on another vm.$on('test', function (msg) { console.log(msg) }) vm.$emit('test', 'hi') // -> "hi" In Vue.js components can

Laravel VueJs component inline template, unknown custom element

老子叫甜甜 提交于 2019-12-02 14:13:38
I tried to use VueJS inline template component inside Laravel 5.7 but facing this error [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option This is my sample code on show.blade.php @extends('layouts.app') @section('content') <div class="content"> <progress-view inline-template> <h1>Test Inline Template Component</h1> </progress-view> </div> @endsection @section('js_after') <script> Vue.component('progress-view', { data() { return {}; }, }); </script> @endsection Default Laravel VueJS instance on app.js

How can I redirect back to previous page after login on vue and laravel?

无人久伴 提交于 2019-12-02 13:43:11
问题 I use vue.js 2 and laravel 5.6 My vue component like this : <template> <a v-if="auth" href="javascript:" class="btn btn-default btn-block" @click="add($event)"> Add </a> <a v-else href="javascript:" class="btn btn-default btn-block" @click="logout"> Add </a> </template> <script> export default { data() { return { auth: App.authCheck } }, methods: { add(event) { ... }, logout() { window.location = '/login?red='+window.location.pathname } } } </script> If the user is not logged in, it will call

How can I make slider in the card deck group on the bootstrap vue?

本小妞迷上赌 提交于 2019-12-02 13:28:00
I make card deck group using this tutorial : https://bootstrap-vue.js.org/docs/components/card/#card-deck-groups My script like this : <template> <div class="animated fadeIn"> <b-card-group deck v-for="row in formattedClubs"> <b-card v-for="club in row" img-src="https://placekitten.com/g/300/450" img-alt="Img" img-top> <h4 class="card-title"> {{club.description}} </h4> <p class="card-text"> {{club.price}} </p> <p class="card-text"> {{club.country}} </p> <div slot="footer"> <b-btn variant="primary" block>Add</b-btn> </div> </b-card> </b-card-group> </div> </template> <script> export default {

Is it possible to emit from mounted in Vuejs?

女生的网名这么多〃 提交于 2019-12-02 11:55:49
I am familiar with emitting data via bus on events and these work great but now I want to emit something but I don't have an event to tie it to. I've tried to emit it on mounted but that hasn't worked as below: mounted(){ bus.$emit('send-test', this.test); }, When you add an event handler in the parent's mounted lifecycle event for an event that is emitted in a child's mounted event, the handler will not catch the event emitted by the child because the handler is added after the child has already emitted the event. Basically the cycle of events is like this. Parent's create Child's create

Vue 2 <keep-alive> not working with <router-view> and key

◇◆丶佛笑我妖孽 提交于 2019-12-02 11:31:11
问题 I'm using vue-router with a series of components like tabs. Each <router-link> is a tab and the space below is the <router-view> . Two of the tabs are the same component with different filters, let's say they are products and the router adds a parameter for filtering: /products/new & /products/sale . Inside of products are individual product components which get mounted when the route is opened. My problem is that when I switch between the routes, and the filter parameter is changed, the

Vuex store with “strict: true” does not work

馋奶兔 提交于 2019-12-02 11:25:49
问题 When I set strict: true I get error: vue.js:525 [Vue warn]: Error in watcher "state" (found in root instance) warn @ vue.js:525 run @ vue.js:1752 update @ vue.js:1720 notify @ vue.js:584 reactiveSetter @ vue.js:814 Transform.resize @ transform.js:169 e.resize @ map.js:343 e._onWindowResize @ map.js:1204 vue.js:1756 Uncaught Error: [vuex] Do not mutate vuex store state outside mutation handlers. at assert (vuex.js:182) at Vue$3.store._vm.$watch.deep (vuex.js:714) at Watcher.run (vue.js:1746)