我有一个输入字段,我想限制用户应输入的小数位数。例如:(10.123),如果他输入更多,则不会进行任何更改,该值将保持不变。现在用户收到一个错误,但这还不够。附言。我正在使用 Vue-Bootstrap。我尝试这样做,但限制整数而不仅仅是小数。
<b-form-input
type="number"
id="contract-input"
v-model="contract"
></b-form-input>
Run Code Online (Sandbox Code Playgroud)
从视图上来看,效果很好。
<p>{{parseFloat(contract).toFixed(2)}}</p>
Run Code Online (Sandbox Code Playgroud) 我尝试在 Docker 中使用 Laravel Sail 运行一个新的 Laravel 9.2 项目。(包含WSL2),索引页在2秒内加载。对于我尝试在 Docker 上运行 Sail 的现有项目,它需要大约 7 秒,而不是在 Laravel Homestead 上运行 0.3 秒。
我在这里找到了类似的帖子:但仍然不起作用。
./vendor/bin/sail up
不再工作“Docker is没有运行”,从我在Laravel 页面上检查的内容来看,我需要 WSL2。docker-compose.yml(由 Laravel Sail 生成)
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway' …
Run Code Online (Sandbox Code Playgroud) 我尝试为maxLength
来自 的输入实现 a bootstrap-vue
,但是从我从他们的文档中读取的内容来看,他们不支持 max. 如果我删除type="number"
,它可以工作,但不再是一个数字。
<b-form-input
size="sm"
v-model="register_volume_first"
type="number"
maxlength=4
placeholder="1902"
></b-form-input>
Run Code Online (Sandbox Code Playgroud) 我在这里找到了一个很好的例子,看起来很适合我的需要,我尝试在我的Vuejs
应用程序中实现它。,但到目前为止,该代码没有检测到任何更改,也没有错误。
data() {
return {
tabFocus:false,
}
}
created() {
this.detectFocusOut();
},
watch:{
tabFocus(value) {
console.log("New value:", value);
},
}
methods:{
detectFocusOut() {
console.log("It is here");
var inView = false;
window.onfocus = window.onblur = window.onpageshow = window.onpagehide = function(
e
) {
if ({ focus: 1, pageshow: 1 }[e.type]) {
if (inView) return;
this.tabFocus = true;
inView = true;
} else if (inView) {
this.tabFocus = !this.tabFocus;
inView = false;
}
};
},
}
Run Code Online (Sandbox Code Playgroud) 我尝试从 foreach 向每个用户添加一些新值,但因为我使用 get,现在我无法在响应上使用分页,但我还需要将该值添加到每个用户。有任何想法吗?
public function statistics()
{
$users = User::select(['id', 'name'])->get();
foreach ($users as $key => $user) {
$history = AnswerHistory::where('user_id', '=', $user->id)->get();
$user->total_votes = count($history);
$user->total_time = gmdate("H:i:s", ($history->sum('answer_time')));
}
return response()->json($users);
}
Run Code Online (Sandbox Code Playgroud) 我有一个管理区域和一个供普通用户使用。现在,当我的会话到期时,我会从管理区域重定向到主页,我必须刷新页面才能将我重定向到/login
. 附注。我使用 Vue.js 作为前端。
我想在会话过期时重定向到我的 /login 页面,而不是主页,那时主页应该是不可见的。
网页.php
// Admin routes
Route::middleware(['can:admin'])->group(function () {
// all routes for admin, and when my session expire I get redirected from here
}
Route::middleware('guest')->get('/', function () {
return redirect('/login');
});
// Normal user routes
Route::middleware('auth')->get('/', function () {
return view('layouts.app');
});
Route::middleware('auth')->get('/{any}', function () {
return view('layouts.app');
})->where('any', '.*');
Run Code Online (Sandbox Code Playgroud)
身份验证服务提供者
public function boot()
{
$this->registerPolicies();
Gate::define('admin', function ($user) {
return !empty($user->roles()->where('admin_area', true)->first());
});
Gate::define('normal', function ($user) {
return !empty($user);
});
} …
Run Code Online (Sandbox Code Playgroud) vue.js ×4
javascript ×3
laravel ×3
vuejs2 ×3
laravel-7 ×2
php ×2
axios ×1
docker ×1
laravel-sail ×1
wsl-2 ×1