英文:
Simple component v-model not updating
问题
以下是您要翻译的内容:
"So I'm finally trying to get my head into the Laravel using Vue scene.
For the life of me, I can't work out why this simple component v-model doesn't seem to be updating the on page content.
<template>
<div class="row">
<div class="col-12">
<div id="card" class="card">
<div class="card-header">
<h4>{{ header }}</h4>
</div>
<div class="card-body">
<input v-model="newItem" type="text" placeholder="title">
<hr>
( {{ newItem }} )
<ul>
<li v-for="item in items" :key="item.id">{{ item.label }}</li>
</ul>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "add-category",
data() {
return {
header: 'Add Category',
newItem: '',
items: [
{ id: 1, label: 'TESTING 123' },
{ id: 2, label: 'TESTING ABC' },
]
}
},
methods: {
}
}
</script>
No matter what text is added in the input, the content between the ( ) never updates and remains blank?
I was following this vue tutorial video here: https://vueschool.io/lessons/user-inputs-vue-devtools-in-vue-3?friend=vuejs
From what I can tell, it should be working?
Could this be a conflict related to Laravel potentially?
Any thoughts are much appreciated."
英文:
So I'm finally trying to get my head into the Laravel using Vue scene.
For the life of me, I can't work out why this simple component v-model doesn't seem to be updating the on page content.
<template>
<div class="row">
<div class="col-12">
<div id="card" class="card">
<div class="card-header">
<h4>{{ header }}</h4>
</div>
<div class="card-body">
<input v-model="newItem" type="text" placeholder="title">
<hr>
( {{ newItem }} )
<ul>
<li v-for="item in items" :key="item.id">{{ item.label }}</li>
</ul>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name:"add-category",
data(){
return {
header: 'Add Category',
newItem: '',
items: [
{id: 1, label:'TESTING 123'},
{id: 2, label:'TESTING ABC'},
]
}
},
methods:{
}
}
</script>
No matter what text is added in the input, the content between the ( ) never updates and remains blank?
I was following this vue tutorial video here:https://vueschool.io/lessons/user-inputs-vue-devtools-in-vue-3?friend=vuejs
From what I can tell, it should be working?
Could this be a conflict related to Laravel potentially?
Any thoughts are much appreciated.
答案1
得分: 0
如此看来,我的问题似乎出在我如何设置 app.js 上,或者说我应该说没有设置,因为它似乎并没有通过 Laravel 使用 Vue,而是通过主 HTML 文件上的一个包含。
所以我移除了那些包含,并将我的 app.js 更改为以下内容,一切都按预期开始工作了!
require('./bootstrap')
// 1. 定义路由组件。
const Home = { template: '<div>Home</div>' }
const About = { template: '<div>About</div>' }
import Welcome from './components/App.vue';
import CategoryList from './components/category/List.vue';
import CategoryCreate from './components/category/Add.vue';
import CategoryEdit from './components/category/Edit.vue';
// 2. 定义一些路由
const routes = [
{ path: '/', component: Home },
{ path: '/about', component: About },
{ path: '/welcome', component: Welcome },
{ path: '/category', component: CategoryList },
{ path: '/category/:id/edit', component: CategoryEdit },
{ path: '/category/add', component: CategoryCreate },
]
window.axios = require("axios");
import { createRouter, createWebHistory } from 'vue-router';
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
window.Vue = require("Vue");
const app = Vue.createApp({})
app.use(router)
app.mount('#app')
所以现在我的 v-model 更新如预期一样!
英文:
So it seems like my issue was with how I had my app.js setup, or should I say wasn't setup as it didn't seem to be using vue via Laravel rather via an include on the main html file.
So I have removed those includes and changed my app.js to the following and it all started working as expected!
require('./bootstrap')
// 1. Define route components.
const Home = { template: '<div>Home</div>' }
const About = { template: '<div>About</div>' }
import Welcome from './components/App.vue';
import CategoryList from './components/category/List.vue';
import CategoryCreate from './components/category/Add.vue';
import CategoryEdit from './components/category/Edit.vue';
// 2. Define some routes
const routes = [
{ path: '/', component: Home },
{ path: '/about', component: About },
{ path: '/welcome', component: Welcome },
{ path: '/category', component: CategoryList },
{ path: '/category/:id/edit', component: CategoryEdit },
{ path: '/category/add', component: CategoryCreate },
]
window.axios = require("axios");
import { createRouter,createWebHistory} from 'vue-router'
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
window.Vue = require("Vue");
const app = Vue.createApp({})
app.use(router)
app.mount('#app')
So now my v-model updates as expected!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论