是否可以从编译视图执行 javascript 代码?我需要在我的 index.blade 文件中编写一些 js 代码来处理一些事件。我尝试了 3 种方法,但它们都不起作用。
控制器。
$advertisements = Advertisement::get();
$view = View::make('test::admin/index',['advertisements'=> $advertisements]);
$html = $view->render();
return $html;
index.blade.php
@push('stackscript') // NOT WORKING
<script>
alert();
</script>
@endpush
<script> // NOT WORKING
alert();
</script>
@section('footer_script') // NOT WORKING
<script>
alert();
</script>
@endsection
<div class="row">
@foreach ($advertisements as $advertisement)
<div class="col-md-9">
<div>{{ $advertisement->title }}</div>
<div>{{ $advertisement->body }}</div>
<div><img src="{{asset($advertisement->image)}}"></div>
</div>
<div class="col-md-3">
<form id="plugin-advertisement" method="POST" action="{{route('plugin.delete-advertisement', $advertisement->id)}}">
@csrf
@method("DELETE")
<button class="btn bnt-sm btn-outline-danger">delete</button>
</form>
</div>
@endforeach
</div>
Vue 组件
window.axios.get(this.url)
.then((res) => {
this.pluginPanel = res.data;
});
template:
<div v-if="!loading" v-html="div(pluginPanel)" />