K
K
Kirill Krasin2018-11-26 11:29:18
JSON
Kirill Krasin, 2018-11-26 11:29:18

How to check if a value exists in a JSON file using Vue.js?

Good afternoon. I just started learning Vue.js, the task is to get data from a JSON file (which I generate myself) and check for the presence of a variable value before displaying it in the body of the document.

JSON file structure:
{
  "appid": "280",
  "name": "Half-Life: Source",
  "developer": "Valve",
  "publisher": "Valve",
  "localization": "sts",
  "localization_released": "2017\/09\/04",
  "game_released": "1 чер 2004",
  "loc_desc": "Локалізація від STS UA у вигляді модифікаці.",
  "short_desc": "Легендарний екшн про доктора Ґордона Фрімена, чий один день на роботі у корпорації «Блек-Меса» змінив увесь світ.",
  "short_desc_steam": "",
  "os_windows": "1",
  "os_linux": "1",
  "os_mac": "1",
  "is_f2p": "1",
  "img1_url": "https:\/\/i.imgur.com\/HS7rqcw.jpg",
  "img1_ur2": "https:\/\/i.imgur.com\/CdNI6EC.jpg",
  "img1_ur3": "https:\/\/i.imgur.com\/xW4FrDs.jpg",
  "price_uah": "169",
  "download_url": "http:\/\/steamcommunity.com\/sharedfiles\/filedetails\/?id=1127260686",
  "translate_url": ""
}

For example, you need to check the translate_url variable and not display the layer surrounding it, for example
<small class="translate_url">Crowdin URL: {{ info.translate_url }}</small>

Code example .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nvdfxx, 2018-11-26
@Mo45

<small v-if="getTranslateURL" class="translate_url">Crowdin URL: {{getTranslateURL}}</small>

computed: {
    getTranslateURL() {
        if(info.translate_url !== '') {
            return info.translate_url
        } else return false
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question