小编Rad*_*dya的帖子

如何使用 Vue Composition API 作为跨组件的全局状态?

所以我尝试使用 Vue Composition API 作为全局状态。例如,我创建了名为useLoading.js加载标志的文件。

useLoading.js

import { reactive, toRefs } from '@vue/composition-api'

export default () => {
  const state = reactive({
    isLoading: false
  })

  const setIsLoading = (loading) => {
    state.isLoading = loading
  }

  return {
    ...toRefs(state),
    setIsLoading
  }
}
Run Code Online (Sandbox Code Playgroud)

setIsLoading然后我创建了组件 A,当单击按钮时它将调用

ComponentA.vue

<template>
  <div @click="showLoading" />
</template>

<script>
import useLoading from '@/composable/useLoading'

export default {
  setup () {
    const { setIsLoading } = useLoading()

    function showLoading () {
      setIsLoading(true)
    }

    return {
      showLoading
    }
  } …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-composition-api

9
推荐指数
1
解决办法
5533
查看次数

我们可以在Swift上重用struct吗?或者还有其他方法吗?

所以我有一个用户JSON结构,如下所示:

- results: {
    meta: {}
    users: []
  },
- status:
Run Code Online (Sandbox Code Playgroud)

我想得到用户所以User我实现的模型来获取JSON是这样的:

struct Response: Decodable {

    let results: Result
    let status: Int
}

struct Result: Decodable {

    let meta: Meta
    let users: [User]
}

struct Meta: Decodable {

    let total_data: Int
    let total_page: Int
}

struct User: Decodable {

    let avatar_url: String
    let created_at: String
    let updated_at: String
    let email: String
    let id: Int
    let name: String
    let username: String
}
Run Code Online (Sandbox Code Playgroud)

它正在工作,但当我有另一个JSON结构相似时,就这样说吧

- results: {
        meta: {}
        rooms: …
Run Code Online (Sandbox Code Playgroud)

json ios swift decodable

1
推荐指数
1
解决办法
183
查看次数

C++数组存储错误的值

我试着输入两个数组,A和B.但每次我输入最后一个B数,除了它改变了B [i + n]的值,它还替换了A [0]的值.这是代码:

#include <iostream>

    using namespace std;

    /*
     * 
     */
    int main(int argc, char** argv) {
        int a[] = {};
        int b[] = {};
        int t, i;

        cout << "Amount of numbers: ";
        cin >> t;

        for (i = 0; i < t; i++) {
            cout << "Enter number for A" << i+1 << ": ";
            cin >> a[i];
            cout << "Enter number for B" << i+1 << ": ";
            cin >> b[i];
        }

        for (i = …
Run Code Online (Sandbox Code Playgroud)

c++ arrays numbers

0
推荐指数
1
解决办法
667
查看次数

标签 统计

arrays ×1

c++ ×1

decodable ×1

ios ×1

javascript ×1

json ×1

numbers ×1

swift ×1

vue-composition-api ×1

vue.js ×1