简要:
我试图联合2个表recipes,posts然后添加->paginate(5)到查询.
但由于某种原因,我得到了这个错误:
基数违规:1222使用的SELECT语句具有不同的列数(SQL :(选择count(*)作为聚合来自
posts
码:
$recipes = DB::table("recipes")->select("id", "title", "user_id", "description", "created_at")
->where("user_id", "=", $id);
$items = DB::table("posts")->select("id", "title", "user_id", "content", "created_at")
->where("user_id", "=", $id)
->union($recipes)
->paginate(5)->get();
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?
没有->paginate(5)查询工作正常.
现在我需要从父组件向子组件发出事件。我在 vue version 3 中看到$on,$off实例$once方法被删除了。应用程序实例不再实现事件发射器接口。
现在我如何可以从 vue 版本 3 中的父组件发出事件并从子组件监听?
为什么我收到警告错误消息:
defineProps引用本地声明的变量。eslint(vue/valid-define-props)
当我在SFC 模式的 props 中使用自定义验证器时<script setup>:
<script setup>
import { validateMarkers } from "./hooks"
import { defineProps } from 'vue'
const props = defineProps({
markers: {
type: [Array, Object],
validator: validateMarkers
}
})
</script>
Run Code Online (Sandbox Code Playgroud)
我的自定义验证器:
export const validateMarkers = (markers) =>
isNotEmpty(markers)
? isObject(markers)
? markerValidator(markers)
: isNotEmptyArray(markers)
? markers.every((marker) => markerValidator(marker))
: error('Undefined type of prop marker')
: null
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个警告?
我有这样的组件:
<template>
<div>
<p>Current coords: <strong>{{ coords }}</strong></p>
<button type="button" @click="updateCoords">
</div>
</template>
<script>
export default {
props: {
coords: {
type: Array,
required: true
}
},
setup(props) {
const updateCoords = () => {
props.coords = [38.561785, -121.449756]
// props.coords.value = [38.561785, -121.449756]
}
return { updateCoords }
},
}
</script>
Run Code Online (Sandbox Code Playgroud)
我尝试使用方法更新 propcoords值updateCoords,但收到错误消息:
未捕获的类型错误:无法设置未定义的属性(设置“坐标”)
在我的情况下如何正确更新 props 值?
我的 laravel 应用程序中有多个守卫:
代码 config/auth.php:
'defaults' => [
'guard' => 'user',
'passwords' => 'users',
],
'guards' => [
'user' => [
'driver' => 'token',
'provider' => 'users',
'hash' => true,
],
'admin' => [
'driver' => 'token',
'provider' => 'admins',
'hash' => true,
]
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => Admin::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' …Run Code Online (Sandbox Code Playgroud) 我尝试使用 VuedefineCustomElement()创建自定义元素,但由于某种原因,子组件样式未包含在影子根中。
然后,我尝试使用本机Element.attachShadow()API而不是使用defineCustomElement()(基于Codesandbox)手动创建影子根,但根本没有加载任何样式:
代码:main.js:
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
let treeHead = document.querySelector("#app");
let holder = document.createElement("div");
let shadow = treeHead.attachShadow({ mode: "open" });
shadow.appendChild(holder);
createApp(App).use(store).use(router).mount(holder);
Run Code Online (Sandbox Code Playgroud)
代码 vue.config.js:
module.exports = {
chainWebpack: (config) => {
config.module
.rule("vue")
.use("vue-loader")
.loader("vue-loader")
.tap((options) => {
options.shadowMode = true;
return options;
});
config.module
.rule("css")
.oneOf("vue-modules")
.use("vue-style-loader")
.tap((options) …Run Code Online (Sandbox Code Playgroud) 如何在构建项目时使用Rollup.js禁用 Vue.js + Vite.js中的分块?
我尝试过这样但对我不起作用:
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: {}
}
}
}
})
Run Code Online (Sandbox Code Playgroud) 当我们在控制器中使用Laravel 表单请求并且验证失败时,表单请求将重定向回errors变量。
redirection当数据无效时,如何禁用并返回自定义错误响应?
我将使用表单请求来GET|POST|PUT请求类型。
我试过这Validator门课来解决我的问题,但我必须使用表单请求。
$validator = \Validator::make($request->all(), [
'type' => "required|in:" . implode(',', $postTypes)
]);
if ($validator->fails()) {
return response()->json(['errors' => $validator->errors()]);
}
Run Code Online (Sandbox Code Playgroud) 我有自定义文本字段,打开对话框时我必须关注它的功能。我尝试使用 vue.js 将其聚焦refs:
代码:
<v-app id="app">
<v-row align="center">
<v-col class="text-center" cols="12">
<v-btn color="primary" @click="openDialog()">Open dialog</v-btn>
</v-col>
</v-row>
<v-dialog v-model="dialog">
<v-card>
<v-card-title
class="headline grey lighten-2"
primary-title
>
Dialog
</v-card-title>
<v-card-text>
<v-row>
<v-col cols="6" class="ml-2">
<v-text-field
ref="name"
placeholder="Enter your name..."
type="text"
solo
flat
outlined
></v-text-field>
<v-btn
color="indigo"
dark
@click = "setFocusName()"
>Set focus</v-btn>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-dialog>
</v-app>
Run Code Online (Sandbox Code Playgroud)
JavaScript:
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
dialog: false
}
},
methods: {
setFocusName() { …Run Code Online (Sandbox Code Playgroud) 现在我编写示例路由而不分组我的Laravel项目的本地化:
Route::get('/{lang?}', function($lang=null){
App::setlocale($lang);
return view('welcome');
});
Run Code Online (Sandbox Code Playgroud)
如何在Laravel 5.6中使用前缀或参数而不是前缀或域路由更正确地创建一组路由?并且可以在前缀和域路由示例中创建本地化:
http://website.com/en
http://en.website.com
Run Code Online (Sandbox Code Playgroud) javascript ×6
vue.js ×6
vuejs3 ×5
laravel ×4
php ×2
vuejs2 ×2
eslint ×1
laravel-4 ×1
laravel-5.6 ×1
pagination ×1
rollupjs ×1
shadow-dom ×1
validation ×1
vite ×1
vue-props ×1
vue-sfc ×1
vuetify.js ×1
webpack ×1