<template>
    <div class="page-cell">
        <co-header title="数据持久化">
            <a @click="goBack()" slot="left">
                <co-button icon="back"></co-button>
            </a>
        </co-header>
        <div class="wrapper">
            <co-cell @click.native="setPrefData" title="设置偏好数据"></co-cell>
            <co-cell @click.native="getPrefData" title="获取偏好数据"></co-cell>
            <co-cell @click.native="removePrefData" title="移除偏好数据"></co-cell>
            <co-cell @click.native="removeAllPrefData" title="清除所有偏好数据"></co-cell>
        </div>
    </div>
</template>
<style>
</style>
<script>
  export default {
    data() {
      return {
        nativeList: []
      };
    },
    methods: {
      goBack: function() {
        history.go(-1);
      },
      // 设置偏好数据
      setPrefData: function() {
        // 入参
        let params = {
          key: 'testkey',
          value: 'testvalue'
        };
        // 执行
        corNative.setPrefData(params);

        // 设置第二个
        params = {
          key: 'key1',
          value: 'value1'
        };
        // 执行
        if (corNative.setPrefData(params)) {
          alert('设置成功');
        } else {
          alert('设置失败');
        }

      },
      // 设置偏好数据
      getPrefData: function() {
        // 入参
        let testvalue = corNative.getPrefData('testkey');
        alert('key：testkey；value：' + testvalue);
      },
      // 移除偏好数据
      removePrefData: function() {
        corNative.removePrefData('testkey');
        let value1 = corNative.getPrefData('testkey');
        let value2 = corNative.getPrefData('key1');
        alert('key:testkey；value:' + value1 + '----key：key1；value：' + value2);
      },
      // 移除偏好数据
      removeAllPrefData: function() {
        corNative.removeAllPrefData();
        let value1 = corNative.getPrefData('testkey');
        let value2 = corNative.getPrefData('key1');
        alert('key:testkey；value:' + value1 + '----key：key1；value：' + value2);
      }
    }
  };
</script>

