简体   繁体   English

Vue 组件:props 未定义

[英]Vue components: props undefinded

When I want to get my variables as props from one vue.js file to antoher it won't work.当我想从一个 vue.js 文件中获取我的变量作为道具时,它将无法正常工作。 I've seen that this issue is quite common but the answers just don't help me.我已经看到这个问题很常见,但答案对我没有帮助。 I can't see what is wrong with my code.我看不出我的代码有什么问题。 Maybe you can have a look at it:也许你可以看看它:

ladedaten.vue: (path: src\components\ladedaten.vue) ladaten.vue: (路径: src\components\ladedaten.vue)

<template>
    <div id="Ladedaten">
        <LadevorgangAendern v-bind:preis="preis"/>  
    </div>
</template>

<script>
import LadevorgangAendern from '../pages/LadevorgangAendern.vue'

export default {
    name: 'Ladedaten',
    components: {LadevorgangAendern},
    data() {
        return {
        preis: 15,           

        }
    },  
}
</script>

LadevorgangAendern.vue (path: src\pages\LadevorgangAendern.vue) LadevorgangAendern.vue(路径:src\pages\LadevorgangAendern.vue)

<template>
    <!--Stuff here-->
    <p>Preis: {{preis}}</p>
</template>

<script>
//some imports here

export default {
    name: 'LadevorgangAendern',
    props: ['preis'],

    data() {
        return {
            //variables 
        }
    }
}

//more stuff here
</script>

In fact I'm not even sure if components are what I need.事实上,我什至不确定组件是否是我需要的。 I want to store data temporarily so when this works I planned to feed ladedaten.vue with values from another pages-file again with props.我想暂时存储数据,所以当这工作时,我计划再次使用道具为 ladaten.vue 提供来自另一个页面文件的值。 In the end I need these values temporarily and changeable.最后,我需要这些值是临时且可变的。 I also thought of sessions but I wanted to try it with components first.我也想到了会话,但我想先用组件尝试一下。 What do you guys think?你们有什么感想?

in LadevorgangAendern.vue, try在 LadevorgangAendern.vue 中,尝试

<p>Preis: {{ this.preis }}</p>

Perhaps try including vuex state management in your application.也许尝试在您的应用程序中包含 vuex state 管理。 Depending on how often or where you want to access your data, its a great way to create a single state throughout the app without having to continually pass props down or emit them back up or using an event bus.根据您想要访问数据的频率或位置,这是在整个应用程序中创建单个 state 的好方法,而无需不断向下传递道具或将它们重新发射或使用事件总线。

https://vuex.vuejs.org/ https://vuex.vuejs.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM