vue-component

Vue not binding data to image src

自作多情 提交于 2020-07-30 07:53:29
问题 I'm having a problem binding data to src attribute in image. This is my code where I have :src and trying to bind image to it. Also I printed this.image in created() and it is getting printed fine. Here is the code <img class="d-block w-100" :src="image" /> export default { name: 'How', data(){ return{ image: '../../assets/img/how_to_oka_6.png' } } } 回答1: You should import that image since it considered as a module like : <img class="d-block w-100" :src="image" /> export default { name: 'How'

dynamically render vue template

孤街浪徒 提交于 2020-07-10 10:26:42
问题 I have vue template data as string. For example, String s = "<div>{{myData}}</div>" And now I want to render in my already defined vue component. <template> <div> HERE I NEED TO PLACE THE STRING </div> </template> <script> export default { name: 'HelloWorld', data: { myData: "IRONMAN" }, } </script> Now I want the output as IRONMAN How can i achieve this? Pleas help. Thanks 回答1: You can have a single file component and do this - I have one called Dynamic.vue which accepts a HTML string - I

dynamically render vue template

早过忘川 提交于 2020-07-10 10:25:46
问题 I have vue template data as string. For example, String s = "<div>{{myData}}</div>" And now I want to render in my already defined vue component. <template> <div> HERE I NEED TO PLACE THE STRING </div> </template> <script> export default { name: 'HelloWorld', data: { myData: "IRONMAN" }, } </script> Now I want the output as IRONMAN How can i achieve this? Pleas help. Thanks 回答1: You can have a single file component and do this - I have one called Dynamic.vue which accepts a HTML string - I

dynamically render vue template

孤街醉人 提交于 2020-07-10 10:25:30
问题 I have vue template data as string. For example, String s = "<div>{{myData}}</div>" And now I want to render in my already defined vue component. <template> <div> HERE I NEED TO PLACE THE STRING </div> </template> <script> export default { name: 'HelloWorld', data: { myData: "IRONMAN" }, } </script> Now I want the output as IRONMAN How can i achieve this? Pleas help. Thanks 回答1: You can have a single file component and do this - I have one called Dynamic.vue which accepts a HTML string - I

How can I keep number and increment in child component with Vue JS?

孤街醉人 提交于 2020-07-10 01:55:52
问题 Practicing to make a todo application with Vue JS Input items save in the localStrage. UPDATED When you have some added list and reload a page, ID number start from 1(defalut). Ideal behaviour: when reload a page, ID number continues number increment. if some items removed, then, add new item, ID number should be the biggest ID number in array(if 8) +1 (should be 9). My code: Link Problem is around here. Child2.vue created() { let keyObject = JSON.parse(localStorage.getItem(this.keyName)); if

Vue Checkbox filter component not working

狂风中的少年 提交于 2020-07-09 13:12:55
问题 In a single file component I made a checkbox array: <label v-for="(category, index) in categories" :key="index" > <input type="checkbox" :value="category.value" @change="emitSearchValue"> <span class="ml-2 text-gray-700 capitalize">{{ category.value }}</span> </label> With EventBus I transfer the data to the List component: methods: { emitSearchValue() { EventBus.$emit('checked-value', 'this.checkedCategories') } } In the List component I listen for the EventBus: created() { EventBus.$on(

Vue Checkbox filter component not working

谁说我不能喝 提交于 2020-07-09 13:12:25
问题 In a single file component I made a checkbox array: <label v-for="(category, index) in categories" :key="index" > <input type="checkbox" :value="category.value" @change="emitSearchValue"> <span class="ml-2 text-gray-700 capitalize">{{ category.value }}</span> </label> With EventBus I transfer the data to the List component: methods: { emitSearchValue() { EventBus.$emit('checked-value', 'this.checkedCategories') } } In the List component I listen for the EventBus: created() { EventBus.$on(

What is the difference between Vuex and Event Bus?

早过忘川 提交于 2020-07-08 09:57:11
问题 I am trying to understand the principle of communication between components and a doubt has arisen: what is the main difference between Vue event bus strategy and Vuex to deal with components communication? Besides that, when is the best time of use of each one and what is the best practice to use both in the same project? 回答1: the vue event bus is a separate instance of Vue. Vuex is a (flux based) state managment library that integrates with the current instance of Vue, and adds a lot of

Vuejs: Show confirmation dialog before route change

老子叫甜甜 提交于 2020-07-04 13:01:22
问题 In my vueJS project, I want to show confirmation dialog before the current route changes. On yes, it should redirect to next desired route otherwise keep it on same route. Any idea how to achieve it? Thanks in advance. 回答1: You can use In-Component Guards beforeRouteLeave . See https://router.vuejs.org/en/advanced/navigation-guards.html . Demo: https://codesandbox.io/s/jzr5nojn39 (try navigating between home, page 1, page 2) Sample Code (using vuejs-dialog as the confirmation dialog):

how can I use console.error or console.log in a vue template?

无人久伴 提交于 2020-07-04 10:09:52
问题 I have a vue component with <form @keydown="console.error($event.target.name);"> gives app.js:47961 [Vue warn]: Property or method "console" is not defined on the instance but referenced during render. window.console doesnt work either what is the proper way to use console and window in a template to debug? 回答1: If you want to run it inline instead of using a method, just add this to the form: Codepen: https://codepen.io/x84733/pen/PaxKLQ?editors=1011 <form action="/" @keydown="this.console