Vuex How to track index and pass it to component?












0















I have two components which gets data from vuex. First component is a slider with images. When you click on image, second component should display information about each picture. How to track index and pass it to the second component to display correct info



Here is my store:



sideSwiperItems: [
{
id: "001",
smallImage: require("@/assets/jpg/sideMenu-01.jpg"),
data: [
{
height: "100 ft",
widht: "10 ft",
},
],
},
{
id: "002",
smallImage: require("@/assets/jpg/sideMenu-02.jpg"),
data: [
{
height: "200 ft",
widht: "20 ft",
},
],
},


first component



swiper-slide.swiper__thumb-position(
v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
:key='idx'
:class=`'slide-'+(idx+1)`
) {{item.smallImage}}


second component



div(
v-for=`(item, idx) in this.$store.state.buildingData.sideSwiperItems`
:key='idx'
)
p.side__block-month
| {{item.data.height}}
| {{item.data.width}}









share|improve this question























  • you track it in the store

    – phoet
    Nov 17 '18 at 15:58
















0















I have two components which gets data from vuex. First component is a slider with images. When you click on image, second component should display information about each picture. How to track index and pass it to the second component to display correct info



Here is my store:



sideSwiperItems: [
{
id: "001",
smallImage: require("@/assets/jpg/sideMenu-01.jpg"),
data: [
{
height: "100 ft",
widht: "10 ft",
},
],
},
{
id: "002",
smallImage: require("@/assets/jpg/sideMenu-02.jpg"),
data: [
{
height: "200 ft",
widht: "20 ft",
},
],
},


first component



swiper-slide.swiper__thumb-position(
v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
:key='idx'
:class=`'slide-'+(idx+1)`
) {{item.smallImage}}


second component



div(
v-for=`(item, idx) in this.$store.state.buildingData.sideSwiperItems`
:key='idx'
)
p.side__block-month
| {{item.data.height}}
| {{item.data.width}}









share|improve this question























  • you track it in the store

    – phoet
    Nov 17 '18 at 15:58














0












0








0


0






I have two components which gets data from vuex. First component is a slider with images. When you click on image, second component should display information about each picture. How to track index and pass it to the second component to display correct info



Here is my store:



sideSwiperItems: [
{
id: "001",
smallImage: require("@/assets/jpg/sideMenu-01.jpg"),
data: [
{
height: "100 ft",
widht: "10 ft",
},
],
},
{
id: "002",
smallImage: require("@/assets/jpg/sideMenu-02.jpg"),
data: [
{
height: "200 ft",
widht: "20 ft",
},
],
},


first component



swiper-slide.swiper__thumb-position(
v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
:key='idx'
:class=`'slide-'+(idx+1)`
) {{item.smallImage}}


second component



div(
v-for=`(item, idx) in this.$store.state.buildingData.sideSwiperItems`
:key='idx'
)
p.side__block-month
| {{item.data.height}}
| {{item.data.width}}









share|improve this question














I have two components which gets data from vuex. First component is a slider with images. When you click on image, second component should display information about each picture. How to track index and pass it to the second component to display correct info



Here is my store:



sideSwiperItems: [
{
id: "001",
smallImage: require("@/assets/jpg/sideMenu-01.jpg"),
data: [
{
height: "100 ft",
widht: "10 ft",
},
],
},
{
id: "002",
smallImage: require("@/assets/jpg/sideMenu-02.jpg"),
data: [
{
height: "200 ft",
widht: "20 ft",
},
],
},


first component



swiper-slide.swiper__thumb-position(
v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
:key='idx'
:class=`'slide-'+(idx+1)`
) {{item.smallImage}}


second component



div(
v-for=`(item, idx) in this.$store.state.buildingData.sideSwiperItems`
:key='idx'
)
p.side__block-month
| {{item.data.height}}
| {{item.data.width}}






vue.js vuex






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 17 '18 at 12:26









Yerlan YeszhanovYerlan Yeszhanov

1501113




1501113













  • you track it in the store

    – phoet
    Nov 17 '18 at 15:58



















  • you track it in the store

    – phoet
    Nov 17 '18 at 15:58

















you track it in the store

– phoet
Nov 17 '18 at 15:58





you track it in the store

– phoet
Nov 17 '18 at 15:58












1 Answer
1






active

oldest

votes


















1














You have to store the data you want to pass into the second element.
For example you want to pass the selected index of the first component, then you have to store the selected object into the store:



sideSwiperItems: [
...
],
selectedObject: null


You can easily assign the selected object like this



swiper-slide.swiper__thumb-position(
v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
@click="onClick"
:key='idx'
:class=`'slide-'+(idx+1)`
) {{item.smallImage}}

methods: {
onClick: (item) => {
this.$store.state.buildingData.selectedObject = item
}
}


If the first and second element is in the same component you can do this without assigning the selected object into Vuex store. Just use the component's data






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351252%2fvuex-how-to-track-index-and-pass-it-to-component%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You have to store the data you want to pass into the second element.
    For example you want to pass the selected index of the first component, then you have to store the selected object into the store:



    sideSwiperItems: [
    ...
    ],
    selectedObject: null


    You can easily assign the selected object like this



    swiper-slide.swiper__thumb-position(
    v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
    @click="onClick"
    :key='idx'
    :class=`'slide-'+(idx+1)`
    ) {{item.smallImage}}

    methods: {
    onClick: (item) => {
    this.$store.state.buildingData.selectedObject = item
    }
    }


    If the first and second element is in the same component you can do this without assigning the selected object into Vuex store. Just use the component's data






    share|improve this answer




























      1














      You have to store the data you want to pass into the second element.
      For example you want to pass the selected index of the first component, then you have to store the selected object into the store:



      sideSwiperItems: [
      ...
      ],
      selectedObject: null


      You can easily assign the selected object like this



      swiper-slide.swiper__thumb-position(
      v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
      @click="onClick"
      :key='idx'
      :class=`'slide-'+(idx+1)`
      ) {{item.smallImage}}

      methods: {
      onClick: (item) => {
      this.$store.state.buildingData.selectedObject = item
      }
      }


      If the first and second element is in the same component you can do this without assigning the selected object into Vuex store. Just use the component's data






      share|improve this answer


























        1












        1








        1







        You have to store the data you want to pass into the second element.
        For example you want to pass the selected index of the first component, then you have to store the selected object into the store:



        sideSwiperItems: [
        ...
        ],
        selectedObject: null


        You can easily assign the selected object like this



        swiper-slide.swiper__thumb-position(
        v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
        @click="onClick"
        :key='idx'
        :class=`'slide-'+(idx+1)`
        ) {{item.smallImage}}

        methods: {
        onClick: (item) => {
        this.$store.state.buildingData.selectedObject = item
        }
        }


        If the first and second element is in the same component you can do this without assigning the selected object into Vuex store. Just use the component's data






        share|improve this answer













        You have to store the data you want to pass into the second element.
        For example you want to pass the selected index of the first component, then you have to store the selected object into the store:



        sideSwiperItems: [
        ...
        ],
        selectedObject: null


        You can easily assign the selected object like this



        swiper-slide.swiper__thumb-position(
        v-for='(item, idx) in this.$store.state.buildingData.sideSwiperItems'
        @click="onClick"
        :key='idx'
        :class=`'slide-'+(idx+1)`
        ) {{item.smallImage}}

        methods: {
        onClick: (item) => {
        this.$store.state.buildingData.selectedObject = item
        }
        }


        If the first and second element is in the same component you can do this without assigning the selected object into Vuex store. Just use the component's data







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 9:08









        Eric MarcelinoEric Marcelino

        52925




        52925






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351252%2fvuex-how-to-track-index-and-pass-it-to-component%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings