小编Rom*_*LTU的帖子

Tailwind CSS 如何编写像素完美的设计

刚开始用https://tailwindcss.com

并且无法弄清楚如何仅使用顺风类对像素完美设计进行编码。简单的例子,我需要 padding-left 22px,但最接近的顺风类是 pl-6 和 pl-8,分别是 24px 和 32px。因此,在一天结束时,我有一堆顺风类 + 1 个自定义,我在其中进行了安排,这违背了该框架“实用程序优先”的目的。

css tailwind-css

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

如何使用 NextJS 13 应用程序路由器将数据从页面传递到布局组件?

我正在努力将数据从子组件传递到布局组件,特别是在布局组件中动态渲染“标题”。下面是我的问题的简化版本。我正在使用最新的 Next.js (13) 应用程序路由器/目录和嵌套布局。

布局:

export default function UsersLayout({children}) {
  <>
    {/* I need the dynamic title here */}
    {children}
  </>
}
Run Code Online (Sandbox Code Playgroud)

页:

export default async function Users() {
  const pageTitle = "Users" // I want to pass this string to the layout

  return (
    <>
      ...
    </>
  );
}
Run Code Online (Sandbox Code Playgroud)

reactjs next.js

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

Laravel Eloquent delete() 不起作用

文档说:

$user = User::find($user_id);

$user->delete();
Run Code Online (Sandbox Code Playgroud)

这不起作用,但是 ProductColor::find($color_id) 工作。$color->delete() 不返回任何内容,DELETE FROM 查询甚至不执行(如调试栏中所示)。

但我可以删除记录:

ProductColor::destroy($color_id);
Run Code Online (Sandbox Code Playgroud)

一定是我之前忽略的东西,我是 Laravel 的新手。

我也在使用商店,它按预期工作

public function store(Request $request)
    {
        $color = new ProductColor();
        $color->name = $request->color_name;
        $color->order = $request->color_order;
        $saved = $color->save();

        if ($saved) {
            return back()->with('message:success', 'Ok');
        } else {
            return back()->with('message:error', 'Error');
        }

    }
Run Code Online (Sandbox Code Playgroud)

总结

这有效

public function destroy($color_id)
    {
        $deleted = ProductColor::destroy($color_id);

        if ($deleted) {
            return back()->with('message:success', 'Deleted');
        } else {
            return back()->with('message:error', 'Error');
        }
    }
Run Code Online (Sandbox Code Playgroud)

这不是

public function destroy($color_id)
{
  $color = ProductColor::find($color_id); …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent laravel-5 laravel-eloquent

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

Woocommerce添加到购物车ajax和迷你购物车

当产品通过ajax添加到购物车时,我需要重新填充迷你购物车.我设法使用过滤器woocommerce_add_to_cart_fragments更新购物车数量,如下所示:

add_filter( 'woocommerce_add_to_cart_fragments', function($fragments) {

    ob_start();
    ?>

    <div class="cart-contents">
        <?php echo WC()->cart->get_cart_contents_count(); ?>
    </div>

    <?php $fragments['div.cart-contents'] = ob_get_clean();

    return $fragments;

} );
Run Code Online (Sandbox Code Playgroud)

我的HTML标记是

<div class="cart-contents">
    <?php echo WC()->cart->get_cart_contents_count(); ?>
</div>
Run Code Online (Sandbox Code Playgroud)

隐藏div女巫的贝娄.cart-contents悬停

<div class="header-quickcart"><?php woocommerce_mini_cart(); ?></div>
Run Code Online (Sandbox Code Playgroud)

我想以与woocommerce_add_to_cart_fragments相同或类似的方式更新此div内容.或者我应该更改HTML标记并将所有内容保存在1 div中?这样做的常用方法或最佳做法是什么?

php ajax wordpress cart woocommerce

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

从node_modules导入SASS部分

尝试使用gulp,panini,mustache,sass和我的一个问题构建自定义工作流程包括来自node_modules的部分内容,这里是main.scss文件的示例:

@import "node_modules/bootstrap/scss/mixins";
@import "settings";
Run Code Online (Sandbox Code Playgroud)

如何避免输入_mixins.scss的完整路径?

sass gulp

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

Tailwind CSS + VueJS 单文件组件与 VS Code 集成

如何正确配置 Tailwind CSS 和 VS Code 以至少禁用 VueJS 单文件组件 (vue-cli) 内有关 at-rule 和空标记错误的错误?

<template>
...
</template>

<style lang="scss">
  body {
    // } expected
    @apply font-source pt-4;
  } // at-rule or selector expected

  h5,h4,h3,h2,h1 {
    // } expected
    @apply font-pt font-bold;
  } // at-rule or selector expected
</style>
Run Code Online (Sandbox Code Playgroud)

css vue.js tailwind-css

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

使用 NextJS13 服务器组件无限滚动(应用程序目录)

目前正在尝试重构我们的项目以使用服务器组件(app 目录),第一个挑战是如何使用新的“app”目录实现无限滚动分页。

这是一个过于简化的页面示例:

import OrganisationInterface from "@/interfaces/OrganisationInterface";

async function getData() {
  const res = await fetch('http://api.test/v1/organisations?page=1');

  if (!res.ok) {
    throw new Error('Failed to fetch data');
  }

  return res.json();
}

export default async function Page() {
  const { data } = await getData();

  return (
      <>
        <div className="mx-auto in-h-screen ">
          {data && data.map((organisation: OrganisationInterface) => (
              <div key={organisation.id}>
                {organisation.attributes.title.lt}
              </div>
          ))}
        </div>
      </>
  );
}
Run Code Online (Sandbox Code Playgroud)

我在服务器上预取了 10 个初始结果,现在我需要发出客户端请求以添加另外 10,20,30...

或者我应该以某种方式在服务器端执行此操作?我需要一些如何正确实现这一点的想法或示例,之前的解决方案完全基于客户端,使用 SWR 或 ReactQuery。

reactjs next.js react-server-components next.js13

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

Laravel View Composer 为每个视图复制 SQL 查询

我需要在大多数视图中访问一些数据(用户详细信息)。我做了什么:

我创建了 ComposerServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ComposerServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer(
            ['includes.header','profile'],
            'App\Http\ViewComposers\CustomerComposer'
        );

    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
Run Code Online (Sandbox Code Playgroud)

创建 CustomerComposer 类

<?php

namespace App\Http\ViewComposers;

use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Modules\Customers\Entities\CustomerDetail;

class CustomerComposer
{
    public $customer = [];

    /**
     * Bind data to the view.
     *
     * @param …
Run Code Online (Sandbox Code Playgroud)

php mysql laravel blade laravel-5

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

Livewire 如何在选择更改时 $emit 事件 (wire:model)

Livewire 如何在<select>更改时$emit 事件(wire:model)

我需要在简单的<select>更改时触发事件(从另一个组件中的 DB 获取一些数据)。

<select id="hall" wire:model="hall_id">...</select>
Run Code Online (Sandbox Code Playgroud)

如何观察这个模型的变化?在 VueJS 上,我们只设置 $watch 或 $computed 属性,我相信 livewire 应该是类似的。奇怪的是为什么没有wire:change指令。

这就是我现在尝试发出事件的方式:

<?php

namespace App\Http\Livewire;

use App\Models\Event;
use App\Models\Hall;
use Livewire\Component;

class ShowReservationForm extends Component
{
    public $hall_id = '';

    protected $queryString = [
        'hall_id' => ['except' => ''],
    ];

    public function mounted()
    {
        //
    }

    public function updatedHallId($name, $value)
    {
        $this->emit('hallChanged', $value);
    }

    public function render()
    {
        return view('livewire.show-reservation-form', [
            'halls' => Hall::all(),
        ]);
    }

    public …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-livewire

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

Vue.js依赖选择

我正处于初学阶段学习Vue.js并遇到了我现在无法弄清楚的问题.所以我有1个选择字段:

data: {
  list: {
    'Option 1': [ { size:'1',prize:'5' }, { size:'2',prize:'10' } ]
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我填充第一个选择字段,如下所示:

<select v-model="firstOptions" v-on:change="onChange">
  <option v-for="(item, index) in list">{{ index }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)

此时一切都很好,但如何根据第一个选择填充另一个选择字段?我需要访问尺寸和价格.

我认为这应该在这里完成:

methods: {
  onChange: function() {
   // get options for second select field
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vuejs2

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

Laravel 无法为用户模型创建策略

无法为用户模型创建策略。

我创建了这样的策略

php artisan make:policy UserPolicy --model=User

获得带有 CRUD 操作的 UserPolicy.php。

然后在 AuthServiceProvider.php 我添加

protected $policies = [
        // 'App\Model' => 'App\Policies\ModelPolicy',
        User::class => UserPolicy::class,
    ];
Run Code Online (Sandbox Code Playgroud)

但什么也没有发生。据我了解,默认情况下为用户模型生成的策略在每个操作上都返回 false,我什至将其明确添加到 UserPolicy 类中:

public function create(User $user)
{
    return false;
}
Run Code Online (Sandbox Code Playgroud)

还可以创建用户。

稍后我将需要检查用户是否尝试编辑自己的帖子。除了编辑自己的配置文件(模型)之外,所有非管理员用户都应该被禁止。

我一定遗漏了一些明显的东西。

更新:

如果我把

$this->authorize('create', $user);
Run Code Online (Sandbox Code Playgroud)

在UsersController的create方法中,会调用create方法Policy,所以看出来有问题

...
use App\Policies\UserPolicy;
use App\User;
...

protected $policies = [
            // 'App\Model' => 'App\Policies\ModelPolicy',
            User::class => UserPolicy::class,
        ];
Run Code Online (Sandbox Code Playgroud)

在 AuthServiceProvider 中。

php laravel

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

枚举扩展或使用特征(可重用性)

我的枚举必须具有用于翻译目的的附加方法:

<?php

declare(strict_types=1);

namespace App\Enums;

enum GenderEnum: string
{
    case MALE = 'male';
    case FEMALE = 'female';

    public function trans(): string
    {
        return trans('enums.' . $this->value);
    }
}
Run Code Online (Sandbox Code Playgroud)

这个方法是反式的,它会在所有枚举中重复,我怎样才能避免重复?我无法使用枚举中的特征来扩展它。

php enums laravel php-8.1

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

VueJS 和动态标题

尝试使用vue-meta

我无法理解如何根据 XHR 响应设置标题。到目前为止,我有:

<script>
    export default {
        name: 'Model',
        data() {
            return {
                model: [],
            }
        },
        metaInfo: {
            title: 'Default Title',
            titleTemplate: '%s - site slogan'
        },
        methods: {
            getModels() {
                window.axios.get(`/api/${this.$route.params.manufacturer}/${this.$route.params.model}`).then((response) => {
                    this.model = response.data;
                    this.metaInfo.title = response.data.model_name; // THIS NOT WORKING
                });
            }
        },
        watch: {
            $route(to, from) {
                if ( to.name === 'model' ) {
                    this.getModels();
                }
            },
        },
        created() {
            this.getModels();
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

当我尝试设置

this.metaInfo.title = response.data.model_name;
Run Code Online (Sandbox Code Playgroud)

获取错误:未捕获(承诺)TypeError:无法设置未定义的属性“title”

所以 this.metaInfo 是未定义的... …

vue.js vue-router vue-component vuejs2

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