vue-component

How To Create a Reusable Form Vue Component

断了今生、忘了曾经 提交于 2019-12-01 00:03:23
Let's say I want to create a contact form. In this contact form, a user can have multiple addresses. I would think that this is a perfect opportunity to use a Vue Component so that I don't have to create redundant address form fields. I would then be able to use this component in different areas of a website, say on edit, create, etc.... How would I go about creating a form component that a parent can use and have values from that form get added to an addresses array? Also, I would like to be able to populate this form with existing values if it's being edited. I've tried different things but

POST file along with form data Vue + axios

佐手、 提交于 2019-11-30 22:27:47
I have a method for Vuejs component: async submit () { if (this.$refs.form.validate()) { let formData = new FormData() formData.append('userImage', this.avatarFile, this.avatarFile.name) this.avatarFile = formData try { let response = await this.$axios.post('http://localhost:3003/api/test.php', { avatar: this.avatarFile, name: this.name, gender: this.gender, dob: this.DOB, }, { headers: { 'Content-Type': 'multipart/form-data; boundary=' + formData._boundary } }) if (response.status === 200 && response.data.status === 'success') { console.log(this.response) } } catch (e) { console.log(e) } } }

Vuejs Search filter

风流意气都作罢 提交于 2019-11-30 22:25:27
I'm new to Vue.js, so thanks for the help!! I have a table that is presenting a list of items that I got using the following code: interface getResources { title: string; category: string; uri: string; icon: string; } @Component export default class uservalues extends Vue { resources: getResources[] = []; created() { fetch('api/Resources/GetResources') .then(response => response.json() as Promise<getResources[]>) .then(data => { this.resources = data; }); } } And this is my table <div class="panel panel-default"> <div class="panel-heading" style="font-weight:bold"><span class="glyphicon

Vue - access nested childs using ref

白昼怎懂夜的黑 提交于 2019-11-30 20:35:12
I have vue component which I use inside himself - data can have array with subelements and I use this array to render them in loop, and next level, next level etc. according to nesting level. Now I would like to run child method from parent and then - if statements are ok, also call it to child, next level etc. I use <mycomponent ref="myFirstLevelRefName" (...) ></mycomponent> and then: this.$refs.myFirstLevelRefName to call first-level childs. But what about about child nodes? I use them in view in that way: <mycomponent v-for="(subElement, index) in getSubelements()" ref="???" v-bind:data=

Vue. How to get a value of a “key” attribute in created element

浪尽此生 提交于 2019-11-30 20:11:49
I try to create a components and get its key for using in axios. Elements created, but I can't get a key. It's undefined <div class="container" id="root"> <paddock is="paddock-item" v-for="paddock in paddocks" :key="paddock.key" class="paddock"> </paddock> </div> <script> var pItem = { props: ['key'], template: '<div :test="key"></div>', created: function() { console.log(key); } }; new Vue({ el: '#root', components: { 'paddock-item': pItem }, data: { paddocks: [ {key: 1}, {key: 2}, {key: 3}, {key: 4} ] } }) </script> I try some variants, but no result - @key was empty. This answer answers the

vue wrap another component, passing props and events

半世苍凉 提交于 2019-11-30 20:01:28
How can I write my component to wrap another vue component, while my wrapper component get some extra props? My wrapper template component should be: <wrapper-component> <v-table></v-table> <!-- pass to v-table all the props beside prop1 and prop2 --> </wrapper-component> and the wrapper props: props: { prop1: String, prop2: String } Here I want to wrap a table component, and pass to the table component all the props and events that were passed to the wrapper, beside two extra props prop1 and prop2 . What is the correct way of doing this in vue? And is there a solution for events too? Place

Vuejs Search filter

爱⌒轻易说出口 提交于 2019-11-30 17:40:37
问题 I'm new to Vue.js, so thanks for the help!! I have a table that is presenting a list of items that I got using the following code: interface getResources { title: string; category: string; uri: string; icon: string; } @Component export default class uservalues extends Vue { resources: getResources[] = []; created() { fetch('api/Resources/GetResources') .then(response => response.json() as Promise<getResources[]>) .then(data => { this.resources = data; }); } } And this is my table <div class=

[Vue warn]: Failed to mount component: template or render function not defined in Webpack 4

与世无争的帅哥 提交于 2019-11-30 17:29:49
问题 I started getting this error once I upgraded to Webpack and related dependencies to v4: [Vue warn]: Failed to mount component: template or render function not defined. Here's the relevant snippets of my package.json and webpack.config.js before and after: Before upgrade: package.json { "dependencies": { "vue": "^2.5.0", "vue-template-compiler": "^2.5.0" }, "devDependencies": { "babel-core": "^6.9.0", "babel-loader": "^6.2.4", "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-transform

How to evaluate Vue.js component props in the data property?

本秂侑毒 提交于 2019-11-30 16:40:11
问题 I have 2 components: Post and Comments . Inside Post component, there is Comments component that has 3 props: postId , numCom (number of comments) and comments (array). I get comments and I pass the array with props, and now I want to retrieve the array in Comments component and add it to data so I can then add/remove comments etc. Here is my code in Comments.vue : props: ['id', 'numCom', 'comments'], data: function() { return { newMessage: "", loading: false, allComments: this.comments, num:

Toggle inside v-for items affects the entire list, how can I make the each toggle affect only the containing list item?

我的未来我决定 提交于 2019-11-30 15:55:23
问题 I'm making a list of items with v-for loop. Inside each item of the loop there is button with click event method that showing description text. When i click on the button, it should toggle only inside it's own item, but it affecting all elements in v-for list. So, how to make a toggle method that will affect only it's own item? <template> <div> <div v-for="item in items" :class="{ activeclass: isActive }"> <div class="item-text"> {{item.text}} </div> <button @click="toggle()">show</button>