LoginSignup
14
11

More than 3 years have passed since last update.

[Vue.js]Vue.jsでLocalStrageを使う

Last updated at Posted at 2019-06-06

src/plugins/VueLocalStrage.js


export default {
  install(vue) {
    vue.prototype.$storage = {
      get(key) {
        // localstrageからとる
        return localStorage.getItem(key)
      },
      set(key, value) {
        // localstrageへ保存
        localStorage.setItem(key, value)
      },
    }
  },
}

使うところ


<script>

/////////////// 省略 ///////////////

methods: {
  setLocalStrage(){
        // ローカルストレージに値を保存する
        this.$storage.set('email', this.email)
  },
  sgtLocalStrage(){
        // ローカルストレージに値を取得する
        this.$storage.get('email', this.email)
  },
}

</script>

14
11
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
14
11