Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ookma-Kyi's avatar

Refactoring Vue template causes errors

I'm trying to refactor the create Vue Template (resources/js/Pages/duels/create.vue):

Here is what I came up with for (resources/js/Pages/duels/create.vue):

And I refactored the offensive fieldsets into a partial((resources/js/Pages/duels/Partials/OffensiveMovesFieldsets.vue) which I intend to do the same for the defensive moves:

However when I try to access the page now I get the following error and the fields don't appear:

I tried to get help from Lary "QuickDraw" AI but, he kept crashing for some reason... Can anyone please help?

0 likes
2 replies
LaryAI's avatar
Level 58

The error you're encountering, TypeError: m.offensive_moves is undefined, suggests that the offensive_moves prop is not being passed correctly to the OffensiveMovesFieldset component. Here are a few steps to troubleshoot and resolve the issue:

  1. Ensure Prop is Passed Correctly: Make sure that the offensive_moves prop is being passed from the parent component (create.vue) to the OffensiveMovesFieldset component. In your create.vue file, you should have something like this:

    <OffensiveMovesFieldset :offensive_moves="props.offensive_moves" />
    

    Ensure that props.offensive_moves is correctly defined and available in the parent component.

  2. Check Prop Definition in Child Component: In your OffensiveMovesFieldset.vue, ensure that the offensive_moves prop is defined correctly:

    <script setup>
    import { defineProps } from 'vue';
    
    const props = defineProps({
        offensive_moves: {
            type: Array,
            required: true
        }
    });
    </script>
    
  3. Verify Data Availability: Ensure that the offensive_moves data is available and correctly populated before the component is rendered. You can add a check in the parent component to ensure that offensive_moves is not undefined or empty before rendering the OffensiveMovesFieldset component.

  4. Debugging: Add some console logs to check the data being passed:

    <script setup>
    import { defineProps } from 'vue';
    
    const props = defineProps({
        offensive_moves: {
            type: Array,
            required: true
        }
    });
    
    console.log('Offensive Moves:', props.offensive_moves);
    </script>
    

    This will help you verify if the data is being passed correctly.

  5. Check Parent Component: Ensure that the parent component (create.vue) is receiving the offensive_moves prop correctly from wherever it is being provided (e.g., from a server response or a parent component).

By following these steps, you should be able to identify and fix the issue with the offensive_moves prop not being passed correctly to the OffensiveMovesFieldset component. If the problem persists, double-check the data flow and ensure that all components are correctly set up to pass and receive props.

Ookma-Kyi's avatar

Sorry @laryai I tried what you suggested, and it still doesn't work. I tried using console.log to debug and it doesn't appear in my Firefox web developer tools console at all. Based on this I have determined that the child values are not being passed to the parent:

Duels/Partials/OffensiveMovesFieldset.vue

Duels/Ceate.vue

Any ideas?

Please or to participate in this conversation.