composer require laravel/ui
php artisan ui vue
npm install vue@next laravel-mix@next
dememiz lazım.npm install vue@next
diyerek Vue3ü yükleyelim.npm install laravel-mix@next
mix.js('resources/js/app.js', 'public/js')
.vue(3)
.version()
.disableNotifications();
require('./bootstrap');
import { createApp } from 'vue';
import App from './components/App.vue';
createApp(App).mount('#app');
npm run dev
veya npm run prod
veya npm run watch
diyebilirim.<div id="app" class="container"></div>
<script src="{{ mix('js/app.js') }}"></script>
npm install vue@latest && npm install --save-dev vue-loader@next
diyerek öncelikle Vue'yu ve Vue Loader'ı projemize ekleyelim.mix.js('resources/js/app-vue.js', 'public/js').vue().version().disableNotifications();
// burada axios'da eklenir ve çalıştırılır
require('./bootstrap');
import Vue from 'vue';
const files = require.context('./', true, /\.vue$/i);
files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));
Vue.config.productionTip = false
// ID'si app olan container element'i bir Vue container'ına dönüşür.
const app = new Vue({
el: '#app'
})
<template>
<div>
<form>
<input type="search" name="q" autocomplete="off" class="form-control" v-model="searchTerm" :placeholder="placeholder">
</form>
<slot :hits="hits"></slot>
</div>
</template>
<script>
export default {
props: [
'token',
'placeholder',
'searchUrl'
],
watch: {
searchTerm() {
axios.get(this.searchUrl + '?q=' + encodeURI(this.searchTerm), {
headers: {
'Authorization': `Bearer ${this.token}`
}
})
.then(response => {
this.hits = response.data;
this.isOpen = true;
})
}
},
data() {
return {
searchTerm: '',
hits: [],
}
},
};
</script>
<hos-search token="{{ $token->plainTextToken }}"
placeholder="Müşteri adını yazarak ara..."
search-url="api/customers">
<template v-slot="{ hits }">
<ul class="list-group">
<a v-for="(hit, index) in hits"
:key="index"
:href="(`customers/${hit.id}`)"
class="list-group-item list-group-item-action">
@{{ hit.name }}
</a>
</ul>
</template>
</hos-search>
<template>
<div>Example Component {{ greeting }}</div>
<div>Foo: {{ foo }}</div>
</template>
<script>
import { ref } from 'vue'
export default {
props: ['Foo'],
setup() {
const greeting = ref('hello there')
return { greeting }
}
}
</script>
<html>
<head></head>
<body>
<div id="app">
<h1>Statik içerik</h1>
<example-component foo="bar"></example-component>
</div>
<script src="{{ mix('js/app.js') }}"></script>
</body>
</html>
import { reactive } from 'vue'
const state = reactive({
term: '',
})
function incrementCount() {
state.count++
}
import { computed } from 'vue'
const itemsLeft = computed(() => state.todos.filter(todo => !todo.inComplete).length)
import { onMounted } from 'vue'
onMounted(() => {
console.log('mounted')
})
export default {}
içerisindeki setup'ta bulunan her şeyi (reactive state declarations, methods, computed props, watchers) dışarda return etmeye gerek kalmadan çalışmasını sağlar.<template>
<div class="mt-4">
<input type="search" name="q" autocomplete="off"
class="form-control" placeholder="Ara..."
v-model="state.searchTerm">
<div class="list-group">
<a v-for="hit of state.hits"
:key="hit.id"
:href="`/resources/${hit.uri}`"
class="list-group-item list-group-item-action">
{{ hit.title }}
</a>
</div>
</div>
</template>
<script setup="props">
import { reactive, watch } from 'vue'
import axios from 'axios'
const state = reactive({
searchTerm: '',
hits: []
})
watch(
() => state.searchTerm,
(newValue, oldValue) => {
axios.get('/api/search?q=' + encodeURI(state.searchTerm))
.then(response => {
state.hits = response.data
})
}
)
</script>
<Link>
component'i var.
<template>
<Link href="/users"
class="text-blue-500 hover:underline"
:class="{'font-bold underline': $page.component === 'Users' }>
Users
</Link>
</template>
<script>
import { Link } from '@inertiajs/inertia-vue'
export default {
components: { Link },
}
</script>
bunu <NavLink>
diye ayrı bir komponente dönüştürmek istiyorum.
<template>
<Link class="text-blue-500 underline"
:class="{'font-bold underline' : active}">
<slot />
</Link>
</template>
<script>
import { Link } from '@inertiajs/inertia-vue'
export default {
components: { Link },
props: {
active: Boolean,
}
}
</script>
<template>
<NavLink href="/users" :active="$page.component === 'Users'">
Users
</NavLink>
</template>
<script>
import { NavLink } from './NavLink'
export default {
components: { NavLink },
}
</script>
<template>
<Link href="/">Refresh</Link>
</template>
<script setup>
import { Link } from '@inertiajs/inertia-vue3';
</script>