M
M
Matvey Uvarov2018-10-31 16:25:58
Vue.js
Matvey Uvarov, 2018-10-31 16:25:58

How to intercept the exported value from the vue array for insertion into the js code?

Please tell me how to "pull" the value from the vue array and insert it into the js code, in the right (marked) place? In html everything works, but in js it displays an error. I rummaged through the Internet, but did not find anything like it.

<template>
      <v-app>
    .
    .
    .
              <v-list>
                <v-list-tile
                  v-for="(item, index) in menuItems"
                  :key="index"
                  :href="'/'+item.locale"   <!-- тут экспортируемое значение item.locale нормально работает -->
                  @click="buttonClick"
                >
                  <v-list-tile-title>{{ item.title }}</v-list-tile-title>
                </v-list-tile>
              </v-list>
    .
    .
    .
      </v-app>
    </template>

// импортируем библиотеку tiny-cookie
      import { getCookie, setCookie } from 'tiny-cookie'

      export default {
        data: () => ({
          dialog: false,
          drawer: null,
          menuItems: [
            { locale: 'ru', title: 'Русский' },
            { locale: 'en', title: 'English' },
            { locale: 'ko', title: '한국어' }
          ],
        }),
        methods:{
          buttonClick: function() {

            // пишем локаль в кукисы
            const flag = true
            setCookie('flag', flag)
            setCookie('language', item.locale ) // сюда нужно вставить, но item.locale выдает ошибку
          }
        },
        props: {
          source: String
        }
      }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Sedyshev, 2018-10-31
@zoddak

<v-list>
                <v-list-tile
                  v-for="(item, index) in menuItems"
                  :key="index"
                  :href="'/'+item.locale"   <!-- тут экспортируемое значение item.locale нормально работает -->
                  @click="buttonClick(index)"
                >
                  <v-list-tile-title>{{ item.title }}</v-list-tile-title>
                </v-list-tile>
              </v-list>

buttonClick: function(index) {

            // пишем локаль в кукисы
            const flag = true
            setCookie('flag', flag)
            setCookie('language', this.menuItems[index].locale ) // сюда нужно вставить, но item.locale выдает ошибку
          }

M
Matvey Uvarov, 2018-10-31
@zoddak

Alexey, so here's where - v-for="(item, index) in menuItems" ... Works in html tags,
but not in script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question