我有一个简单的问题,希望你能提供帮助:
<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) 我在组件中找到了异步计算方法的解决方案:
目前,我的组件是:
<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模式来异步计算.
您好,我有一个关于确认协议“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”
这是我的〜/ 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?
我使用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 对象 …
我最近开始使用 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)
但我认为这不是最好的方法。希望大家有更好的解决方案。
我有一个视图集 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) 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) 我正在寻找一种在 VueJS 中缓存 http 响应数据的最佳方法,现在我将 Vuex Store 用于我的博客。我想在请求到服务器时缓存所有响应数据。
具体来说,这是我的博客:
当我通过路由器请求数据到博客详细信息1, 3, 4 时,我有响应数据。如何缓存它,然后在同一会话中重新路由到 1、3、4,它不会重新获取数据并获取数据缓存以显示?
现在我使用 Vuex,如果必须存储太多数据,我认为它很慢。
这是一个简单的问题,但我不知道使用 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 ×5
vuejs2 ×5
django ×2
python ×2
axios ×1
ecmascript-6 ×1
javascript ×1
pymongo ×1
pymongo-3.x ×1
python-3.x ×1
swift ×1
swiftui ×1
vuex ×1