Skip to content

How do you get your axios calls out of being wrapped in a proxy? #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
delebash opened this issue Sep 30, 2023 · 0 comments
Open

How do you get your axios calls out of being wrapped in a proxy? #13

delebash opened this issue Sep 30, 2023 · 0 comments

Comments

@delebash
Copy link
Contributor

delebash commented Sep 30, 2023

In the past when I needed to get an array that was wrapped in the vue proxy I would just use toRaw but that is not working.

I am trying to add a permission gui to add permissions to roles.

In the roles/Edit.vue I have added a little listbox control and am loading like so

const {role: postData, getRole, updateRole,getRolePermissions, rolePermissionList,validationErrors, isLoading} = useRoles()
const {permissions, getAllPermissions} = usePermissions()

onBeforeMount( () => {
    getRolePermissions(route.params.id)
    getAllPermissions()
    console.log(toRaw(permissions))
    // const difference =
    //     permissions.filter((element) => !rolePermissionList.includes(element));

    availablePermissions = permissions
    currentPermissions = rolePermissionList
})

It binds successfully to my listbox but I need to do a diff for availablePermissions, when I try to do the diff the getAllPermissions is still wrapped in a vue proxy and it won't work. I followed your example to create getAllPermissions() axois call.

 const getAllPermissions = async () => {
        axios.get('/api/permissions/')
            .then(response => {
                permissions.value = response.data.data;
            })
    }

This is what the proxy looks like

RefImpl {__v_isShallow: false, dep: undefined, __v_isRef: true, _rawValue: Array(0), _value: Proxy(Array)}
dep
: 
Set(1) {ReactiveEffect}
__v_isRef
: 
true
__v_isShallow
: 
false
_rawValue
: 
(20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
_value
: 
Proxy(Array) {0: {…}, 1: {…}, 2: {…}, 3: {…}, 4: {…}, 5: {…}, 6: {…}, 7: {…}, 8: {…}, 9: {…}, 10: {…}, 11: {…}, 12: {…}, 13: {…}, 14: {…}, 15: {…}, 16: {…}, 17: {…}, 18: {…}, 19: {…}}
value
: 
(...)
[[Prototype]]
: 
Object

I have tried adding the .value to permissions and it returns an empty array even though the proxy array is not empty

Here is what my control looks like

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant