component1.vue 984 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <view class="content">
  3. <button type="primary" @click="saveData">存储数据</button>
  4. <button type="primary" @click="getData">获取数据</button>
  5. <view>
  6. <hello></hello>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import hello from '../../components/hello/hello.vue';
  12. export default {
  13. components: { hello },
  14. data() {
  15. return {};
  16. },
  17. methods: {
  18. saveData() {
  19. uni.setStorage({
  20. key: "user",
  21. data: {
  22. id: 3241354,
  23. name: "asdfasf",
  24. age: 18,
  25. sex: "男",
  26. },
  27. success() {
  28. console.log("success");
  29. },
  30. fail(err) {
  31. console.log(err);
  32. },
  33. });
  34. },
  35. getData() {
  36. uni.getStorage({
  37. key: "user",
  38. success(res) {
  39. console.log(res);
  40. },
  41. fail(err) {
  42. console.log(err);
  43. },
  44. });
  45. },
  46. },
  47. };
  48. </script>
  49. <style>
  50. .content {
  51. margin: 20rpx;
  52. }
  53. </style>