component1.vue 1.3 KB

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