vue-component

How to share data between components in VueJS

一曲冷凌霜 提交于 2019-12-03 04:14:34
问题 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? 回答1: 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

Can you render VNodes in a Vue template?

筅森魡賤 提交于 2019-12-03 03:49:38
I have an situation where I have a render function that passes some data to a scoped slot. As part of this data I'd like to include some VNodes constructed by the render function that could optionally be used by the scoped slot. Is there anyway when writing the scoped slot in a template to output the raw VNodes that were received? You can use a functional component to render the vnodes for that section of your template: <some-component> <div slot-scope="{ vnodes }"> <vnodes :vnodes="vnodes"/> </div> </some-component> components: { Vnodes: { functional: true, render: (h, ctx) => ctx.props

How does Vue.js reactivity work under the hood?

﹥>﹥吖頭↗ 提交于 2019-12-03 03:49:00
Basically, when I have a component, let’s call it “TransportComponenet.vue”, and in that component, I have a data() and My properties are carId, transportId. What vue does is makes getters and setters for these properties. Let’s say in this componenet’s view, I type {{carId + transportId}} and also {{carId * transportId}} . As far As I know, Vue comes to my views, looks at them, and wherever I have getters ( {{carId+ transportId}} or {{carId * transportId}} ) are getters. So vue comes and registers them in component’s watcher. When I somewhere use setters such as this.carId = 5 . Vue does the

Vuejs js for multiple pages, not for a single page application

♀尐吖头ヾ 提交于 2019-12-03 03:25:43
问题 I need to build an application using laravel 5.3 and vuejs 2, because I need to use two-way binding rather than use jquery. I need to set up the views with blade templates. Then, I need to use vuejs in each page as mentioned below. resources/asserts/js/components/List.vue <script> const panel = new Vue({ el: '#list-panel', name: 'list', data: { message: 'Test message' }, methods: { setMessage: function(){ this.message = 'New message'; } } }) </script> resources/asserts/views/post/index.blade

How to encapsulate the common functionality in a Vuejs project? Best Practice

血红的双手。 提交于 2019-12-03 02:58:53
I am working with a mid size project utilizing Vuejs as the front-end. The options I am exploring to encapsulate / separate the common methods which may be used in many components include mixins approach and plugin approach. Mixin Approach I have to write an import statement in each of the component (file) where I want to use the mixin methods. Does this increase the final file size as the mixin will be imported at multiple places? I can use this within the mixin methods. Plugin Approach I can install the plugin globally with Vue.use(MyPlugin) and use the plugin in any component without

How to use VueJS 2 global components inside single file components?

大城市里の小女人 提交于 2019-12-03 01:22:37
I am trying to use a globally registered component (with Vue.component ) inside a single file component but I am always getting vue.common.js:2611[Vue warn]: Unknown custom element: <my-component> - did you register the component correctly? For example: main.js: ... Vue.component('my-component', { name: 'my-component', template: '<div>A custom component!</div>' }) ... home.vue: <template> <div> <my-component></my-component> </div> </template> <script> module.exports = { name: 'home' } </script> If I register it locally, it works OK: <template> <div> <my-component></my-component> </div> <

Vue-Router Passing Data with Props

混江龙づ霸主 提交于 2019-12-03 00:37:08
I am having a hard time passing props using Vue-Router. I seem to not be able to access the props when I bring them into the next view. This is my methods object: methods: { submitForm() { let self = this; axios({ method: 'post', url: url_here, data:{ email: this.email, password: this.password }, headers: { 'Content-type': 'application/x-www-form-urlencoded; charset=utf-8' } }).then(function(response) { self.userInfo = response.data; self.$router.push({name: 'reading-comprehension', props: {GUID:self.userInfo.uniqueID }}); }) } } The post request is working, but when I try to route to a new

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

会有一股神秘感。 提交于 2019-12-02 23:26:09
问题 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=

Vue.js - Emit event from directive

瘦欲@ 提交于 2019-12-02 22:57:08
Is it possible to emit a custom event from the directive in the component to which this directive is attached. I was expecting it to work as described in example, but it does not. Example: //Basic Directive <script> Vue.directive('foo', { bind(el, binding, vnode) { setTimeout(() => { //vnode.context.$emit('bar'); <- this will trigger in parent vnode.$emit('bar'); }, 3000); } }); </script> //Basic Component <template> <button v-foo @bar="change">{{label}}</button> </template> <script> export default{ data() { return { label: 'i dont work' } }, methods: { change() { this.label = 'I DO WORK!'; }

How can I activate child category in treeview on the vue component?

半腔热情 提交于 2019-12-02 20:57:16
问题 I have two vue components. My first component (parent component) like this: <template> ... <ul class="filter-category" v-for="list in categories"> <list-category :data="list" :category-id="categoryId"></list-category> </ul> ... </template> <script> ... export default { ... data() { return { categories: [ { id: 1, name: 'England', children: [ { id: 3, name: 'Chelsea', children: [ {id: 7, name: 'Hazard'}, {id: 8, name: 'Morata'} ] }, { id: 4, name: 'Manchester United', children: [ {id: 9, name: