小编Kit*_*Kit的帖子

v-bind中的条件:样式 - VueJS

我有一个简单的问题,希望你能提供帮助:

<div>
  <figure :style="{ 'background': 'url(' + item.main_featured + ') center no-repeat' }">
</div>
Run Code Online (Sandbox Code Playgroud)

如果未定义API中的URL,我希望样式属性"background"返回颜色

例:

如果item.featured_photo不为null:

<figure style="background: url('localhost:6969/image.img') center no-repeat">
Run Code Online (Sandbox Code Playgroud)

如果item.featured_photo为null:

<figure style="background: #FFF">
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs2

24
推荐指数
6
解决办法
4万
查看次数

组件中的异步计算 - VueJS?

我在组件中找到了异步计算方法的解决方案:

目前,我的组件是:

<div class="msg_content">
   {{messages}}
</div>

<script>
export default {
  computed: {
    messages: {
      get () {
        return api.get(`/users/${this.value.username}/message/`, {'headers': { 'Authorization': 'JWT ...' }})
        .then(response => response.data)
      }
    }
  },
}
</script>
Run Code Online (Sandbox Code Playgroud)

结果: {}

如何在Promise模式下重写?因为我认为我们可以通过写入Promise模式来异步计算.

vue.js vue-component vuejs2

18
推荐指数
2
解决办法
2万
查看次数

如何使用符合“Hashable”协议的 ForEach

您好,我有一个关于确认协议“Hashable”的问题。实在是太烂了。这是我的模型:

struct Page: Decodable, Identifiable {
    var id: String
    var name: String
    var thumbnail: String?
    var description: String
    var type: String
    var speechs: [String]
}

struct ExploreDataSource: Decodable, Hashable {   
    var title: String
    var data: [Page]
}
Run Code Online (Sandbox Code Playgroud)

这是我的ForEach代码:

List {
    ForEach(self.VM.dataSource, id: \.self) { item in
        Text(item.title).bold().font(.system(size: 22.0))\
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:

类型“ExploreDataSource”不符合协议“Equatable”。您想添加协议存根吗?类型“ExploreDataSource”不符合协议“Hashable”

swift swiftui

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

在Vuejs中全局导入Axios方法

这是我的〜/ plugins/axios.js文件:

import axios from 'axios'

let api = axios.create({
  baseURL: 'http://localhost:8000/api/v1/'
})

export default api
Run Code Online (Sandbox Code Playgroud)

当我想在每个组件中使用axios时,我必须写下这一行:

import api from '~/plugins/axios

我如何在全球范围内配置它,只需编写$ api?

vue.js axios vuejs2

6
推荐指数
2
解决办法
1万
查看次数

JS:在复杂的父子数组中按字段查找对象

我使用Javascript ES6并遇到问题。

我有一个数组:

var commentList = [
   {'id': 1, text: 'A', children: [{'id': 2, text: 'B' }] },
   {'id': 4, text: 'asd', children: [] },
   {'id': 5, text: 'vx', children: [{'id': 7, text: 'xxss' }] },
   {'id': 8, text: 'ghfdh', children: [{'id': 15, text: 'I want to take this' }] },
   {'id': 10, text: 'A', children: [{'id': 18, text: 'Bsda' }] },
]
Run Code Online (Sandbox Code Playgroud)

这是一个具有父子结构的数组。{'id': 15, text: 'I want to take this' }如果我只有ID,如何获得 Exactly 对象 …

javascript ecmascript-6

6
推荐指数
3
解决办法
7345
查看次数

Pymongo:在响应中删除 $oid 的最佳方法

我最近开始使用 Pymongo,现在我想找到删除 Response 中 $oid 的最佳方法

当我使用时find

result = db.nodes.find_one({ "name": "Archer" }
Run Code Online (Sandbox Code Playgroud)

并得到响应:

json.loads(dumps(result))
Run Code Online (Sandbox Code Playgroud)

结果将是:

{
  "_id": {
  "$oid": "5e7511c45cb29ef48b8cfcff"
  },
  "about": "A jazz pianist falls for an aspiring actress in Los Angeles."
}
Run Code Online (Sandbox Code Playgroud)

我的预期:

{
  "_id": "5e7511c45cb29ef48b8cfcff",
  "about": "A jazz pianist falls for an aspiring actress in Los Angeles."
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我们可以使用:

resp = json.loads(dumps(result))
resp['id'] = resp['id']['$oid']
Run Code Online (Sandbox Code Playgroud)

但我认为这不是最好的方法。希望大家有更好的解决方案。

pymongo pymongo-3.x flask-pymongo

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

需要在 Django Rest Framework 中使用 AnonymousUser 登录

我有一个视图集 API,它获取通过Django JWT进行身份验证的用户的通知,但出现错误。请看一下!

视图集:

from api.notifications.models import Notification 
from rest_framework.generics import ( ListAPIView )
from api.notifications.serializers import ( NotificationListSerializer )
from api.pagination import NewFeedPagination
from rest_framework.permissions import AllowAny
from api.permissions import IsOwnerOrReadOnly

class NotificationListAPIView(ListAPIView):
    permission_classes = [AllowAny]
    serializer_class = NotificationListSerializer
    ordering_fields = 'date'

    def get_queryset(self, *args, **kwargs):
        queryset_list = Notification.objects.filter(to_user=self.request.user)
        return queryset_list
Run Code Online (Sandbox Code Playgroud)

登录并访问 URL 后,即成功。但它没有登录,出现错误:int() argument must be a string or a number, not 'AnonymousUser'。如何设置 AnonymousUser,URL 将进入登录页面:localhost:8000/admin?

所有回溯错误:回溯:

File "C:\Python27\lib\site-packages\django\core\handlers\exception.py" in inner
  41.             response = get_response(request) …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework

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

Bulk Update data in Django Rest Framework

I am creating a Notification apps by Django Rest Framework which users can MARK AS READ ALL notification by using PATCH API in frontend. How can I Bulk Update data can do this task.

This serializer and viewset below just for PATCH only one notification object, but I want to do it all with Notifications which have field is_read = False

Edited with the right way

My Serializers:

class NotificationEditSerializer(ModelSerializer):
    class Meta:
        model = Notification
        fields = (
            'id', …
Run Code Online (Sandbox Code Playgroud)

python django python-3.x django-rest-framework

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

VueJS:缓存 http 响应数据的最佳方式

我正在寻找一种在 VueJS 中缓存 http 响应数据最佳方法,现在我将 Vuex Store 用于我的博客。我想在请求到服务器时缓存所有响应数据。

具体来说,这是我的博客:

当我通过路由器请求数据到博客详细信息1, 3, 4 时,我有响应数据。如何缓存它,然后在同一会话中重新路由到 1、3、4,它不会重新获取数据并获取数据缓存以显示?

现在我使用 Vuex,如果必须存储太多数据,我认为它很慢。

在此处输入图片说明

vue.js vuex vuejs2

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

如何在VueJs中获取子组件的数据?

这是一个简单的问题,但我不知道使用 Vue2 正确执行此操作的最佳方法:

父组件:

<template>
  <div class="parent">
    <child></child>
    {{value}} //How to get it
  </div>
</template>
Run Code Online (Sandbox Code Playgroud)

子组件:

<template>
  <div class="child">
    <p>This {{value}} is 123</p>
  </div>
</template>

<script>
export default {
  data: function () {
    return { value: 123 }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

vue.js vue-component vuejs2

4
推荐指数
1
解决办法
2万
查看次数