LoginSignup
1
1

More than 3 years have passed since last update.

json からデータを検索、取得し computed にて反映

Last updated at Posted at 2019-12-23

vue.js で設定ファイルの json に書く

config.json

  "work":[
    {"key":0,"value":"マッチング後にまずは会いたい"},
    {"key":1,"value":"気が合えば会いたい"},
    {"key":2,"value":"条件が合えば会いたい"},
    {"key":3,"value":"メッセージを重ねて"},
    {"key":4,"value":"その他"}
  ],

jsonを読み込む

hoge.vue

import configJson from '../assets/config.json'

export default {

    data () {
        return {
            configJson:configJson,

対応したデータを取得


computed: {

    work() {
        const key = this.user.work;//2。
        const computed_tmp = this.configJson.work.find((v) => v.key === key);
        return computed_tmp.value;//条件が合えば会いたい
    }

んで取得したデータを表示


{{work}}//条件が合えば会いたい

と表示される。
まぁ、これがベストなんじゃないでしょうか。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1