小编Ale*_*pov的帖子

为什么 useFetch 无法在客户端的 nuxt3 中进行页面更改?

我刚刚开始学习 nuxtjs (有一些 vue.js 经验),我遇到了以下问题:

我有一个简单的todo-[id].vue页面。它应该从 API 获取待办事项并在页面上呈现:

<script setup>
import Section from '~~/components/UI/containers/section.vue';
import ButtonLink from '~~/components/UI/buttons/button-link.vue';

const route = useRoute()
const todoId = parseInt(route.params.id)
const { data: todo } = await useFetch(`https://jsonplaceholder.typicode.com/todos/${todoId}`)
</script>

<template>
  <Section>
    <div class="mt-4 flex space-x-4">
      <ButtonLink :to="{name: 'todo-id', params: {id: todoId - 1}}" type="secondary" v-show="todoId !== 1">previous</ButtonLink>
      <ButtonLink :to="{name: 'todo-id', params: {id: todoId + 1}}">next</ButtonLink>
    </div>
    <div class="mt-6">
      <p class="text-lg" :class="[todo.completed ? 'text-green-600' : 'text-red-600']">{{ todo.title }} (#{{ todo.id }})</p>
    </div>
  </Section> …
Run Code Online (Sandbox Code Playgroud)

nuxt.js nuxtjs3

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

如何仅从雄辩的查询中获取关系

我得到以下代码:

$popularProducts = PopularProduct::with('product')->get();

这就是我从popular_products(仅包含product_id)表中获取所有产品的方式,其中包含表的关系products。但我有这个结果:

Collection {#409 ?
  #items: array:1 [?
    0 => PopularProduct {#411 ?
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:4 [?]
      #original: array:4 [?]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [?
        "product" => Product {#462 ?}
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: …
Run Code Online (Sandbox Code Playgroud)

laravel eloquent

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

How to implement SSR for single vue component inside of laravel application?

I'm working on an laravel project. There're a lot of vue components and I need to make SSR due to SEO. I can't use nuxt.js or something like it because of my app is not SPA. I have default mix settings:

const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.sass', 'public/css');
mix.disableSuccessNotifications();
Run Code Online (Sandbox Code Playgroud)

I put the vue components to laravel views (blade templates) like <example-component></example-component>. How may I implement SSR for there components only in this case?

I need to add this …

laravel vue.js server-side-rendering

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

如何用钥匙搜索收藏品?

我得到以下收藏:

$this->items = collect([$productId => [
                    'name' => $product->title,
                    'price' => $product->price,
                    'is_sale' => $product->is_sale,
                    'sale_price' => $product->sale_price,
                    'sale_percent' => $product->sale_percent,
                    'can_use_promocode' => $product->can_use_promocode,
                    'qty' => 1,
                ]);
]);
Run Code Online (Sandbox Code Playgroud)

如何用钥匙搜索物品?在文档(https://laravel.com/docs/5.2/collections)中,我看不到任何方法

UPD:例如,用户将商品添加到购物车($this->items)。我想检查购物车中物品的存在(需要用钥匙做)。模拟php功能array_key_exists,但用于集合。

php laravel

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

如何在mysql中存储加密货币余额?

提到这个问题。在标记的答案中说,在 mysql 中存储加密货币的最佳方式是将其存储为DECIMAL(27,18)or DECIMAL(36,18)。但那里的评论让我怀疑。如果 ETH 值有 32 个字节,那么我们不能以这种方式存储余额。那么最好的保存方法是什么?

PS 除了字符串,我需要按余额值对钱包进行排序。

mysql

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

尝试刷新令牌时 Axios 拦截器无限循环

我有一个 vue.js SPA 应用程序。我的目标是在令牌通过 axios 拦截器过期时刷新令牌。当用户向api发送请求时,我需要首先检查令牌过期时间,如果过期则刷新它,然后完成用户的请求。

我有一个刷新功能:

const refreshToken = () => {
  return new Promise((resolve, reject) => {
    return axios.post('/api/auth/token/refresh/').then((response) => {
      resolve(response)
    }).catch((error) => {
      reject(error)
    })
  })
}
Run Code Online (Sandbox Code Playgroud)

和axios请求拦截器:

axios.interceptors.request.use((config) => {
  let originalRequest = config
  if (jwt.isTokenExpired()) {
    return api.refreshToken()
      .then(res => {
        if (res.data.error == 'TOKEN_BLACKLISTED' && res.headers.authorization) {
          //get the token from headers without "Bearer " word 
          let token = res.headers.authorization.slice(7)
          //save the token in localStorage
          jwt.setToken(`"${token}"`)
          //refresh "Authorization" header with new token
          api.setHeader() …
Run Code Online (Sandbox Code Playgroud)

javascript interceptor vue.js axios

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

如何做产品过滤器(laravel)

我在网上商店。我有3个页面,其中产品过滤条件相似-目录页面,父类别页面和子类别页面

site/catalog/  // catalogController@index
site/catalog/parentCategory/childrenCategory //childrenCategoryController@index
site/catalog/parentCategory //parentCategoryController@index
Run Code Online (Sandbox Code Playgroud)

过滤器是通过get请求制作的,例如:site/catalog?price_from=1&price_to=9999&color=red。如何使这个过滤器成为一个单独的功能?在产品模型中做到这一点会很好吗?以及如何使用它?我认为这应该是一个接受2个参数(请求参数和当前查询模型)并返回的函数$this

控制器中的代码:

$products = Product::filter($products, $request)->paginate(20);     
Run Code Online (Sandbox Code Playgroud)

模型:

public function filter($model, Request $request) {
        if ($request->has('price_from')) {
            $model->where('price', '>', $request->get('price_from'));
        }
        if ($request->has('color')) {
            $model->where('color', '>', $request->get('color'));
        }

        return $model;
    }
Run Code Online (Sandbox Code Playgroud)

但是怎么做对呢?如何$products在控制器代码中传递电流?

php laravel

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

DOMPDF with laravel - 无法加载 html 文件中的图像

我正在尝试使用 laravel 和 dompdf lib 生成 pdf 文件。这是我的控制器代码:

public function create(Request $request) {
    $pdf = new Dompdf();
    $html = Storage::disk('local')->get('public/pdf/template.html');
    $pdf->loadHtml($html, 'UTF-8');
    $pdf->setPaper('A4', 'portrait');
    $pdf->render();
    $filename = "Hi!";
    return $pdf->stream($filename, ["Attachment" => false]);
}
Run Code Online (Sandbox Code Playgroud)

template.html得到了一些 html,在某个地方我得到了这样的图像:

<img src="img/logo.png" alt="BTS">

但 dompdf 无法写入此图像:Image not found or type unknown。我的文件系统是:

.pdf ...img ......here is images ...template.html ...*some_fonts_files*

但与此同时,字体加载得很好。我应该怎么做才能在 template.html 中渲染图像?

html php render dompdf laravel

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

无法为 api 路由 laravel 设置 cookie

使用后端(laravel)和前端 SPA(vue.js、vue-cli 3)进行服务。我需要通过 httpOnly cookie (不是 localStorage)进行身份验证。我使用tymondesigns/jwt-auth作为 api auth 包。

\n\n

我的环境是:

\n\n
    \n
  • API路线:http://brideplanner.test/api
  • \n
  • SPA路线:http://app-test.brideplanner.test:81/
  • \n
\n\n

我的登录路径是/api/auth/login,控制器方法是:

\n\n
public function login()\n    {\n        $credentials = request([\'email\', \'password\']);\n        $user = User::where(\'email\',\'=\',$credentials[\'email\'])->first();\n        if (!$user || !$token = auth()->claims([\'sub\' => $user->id, \'csrf-token\' => str_random(32) ])->attempt($credentials)) {\n            return response()->json([\'error\' => \'Unauthorized\'], 401);\n        }\n        return response()\n            ->json(\'success\')\n            ->withCookie(\'token\', $token, config(\'jwt.ttl\'), ".brideplanner.test", null, false, false);\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

token但是当我尝试向 API 发送请求时, cookie 存储中没有任何项目。这里出了什么问题?为什么没有令牌?我应该怎么办?

\n\n

UPD:我通过邮递员测试了请求,并得到了令牌:

\n\n
Set-Cookie …
Run Code Online (Sandbox Code Playgroud)

php api laravel laravel-routing

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

如何将 WEI 转换为 ETHER php

我需要将字符串转换0x2fe84e3113d7b为浮点类型。该字符串来自infura.io API作为帐户余额。我尝试使用https://github.com/mbezzanov/ethereum-converter,但在这种情况下没有任何意义(它总是以任何方式返回 0.00000 )。如何0.000842796652117371用php将此字符串转换为?

use Bezhanov\Ethereum\Converter;

...
$this->converter = new Converter();

$weiValue = '0x1e1e83d93bb6ebb88bbaf';
dump($this->converter->fromWei($weiValue)); // returns 0.00000000000000000000000000000000000

$hexValue = hexdec($weiValue); // returns 2.2757423599815E+24
dump($this->converter->fromWei($hexValue)); // returns the same
Run Code Online (Sandbox Code Playgroud)

我猜这是由于值太长造成的$hexValue(我的意思是转换器无法转换长整数)。但是如何从这个十六进制中获取以太值呢?

php ethereum

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

Laravel cookie 自带加密,为什么?

我得到了以下服务提供商:

class CartServiceProvider extends ServiceProvider {
    public function boot() {

    }

    public function register() {
        $this->app->singleton(\Alexxosipov\Cart\Cart::class, function($app) {
            return new \Alexxosipov\Cart\Cart($app['request']);
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

还有我的 Cart 课,我在那里得到了这个:

$this->id = (request()->cookie('cart_id')) ? request()->cookie('cart_id') : false;
Run Code Online (Sandbox Code Playgroud)

request()->cookie('cart_id')返回加密字符串。如果我将在任何控制器中执行此操作,它都可以正常工作。为什么?我应该怎么做才能在 Cart 类中使用它? Laravel 5.5

php laravel laravel-5.5

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