Ferrington
Ferrington
NNuxt
Created by asasinmode on 6/24/2024 in #❓・help
Read and set a value to use inside of template during build time
You can import your package.json and add a property to nuxt.config.ts
import pkg from "./package.json";

export default defineNuxtConfig({
appConfig: {
appVersion: pkg.version,
},
})
import pkg from "./package.json";

export default defineNuxtConfig({
appConfig: {
appVersion: pkg.version,
},
})
Then access it like useAppConfig().appVersion
3 replies
NNuxt
Created by isakwang on 6/17/2024 in #❓・help
v-for where v-if only affects one element
Or create a separate object to track it, with the key being an item id
4 replies
NNuxt
Created by isakwang on 6/17/2024 in #❓・help
v-for where v-if only affects one element
If you add an isExpanded property to each item you can have:
<div
v-for="item in list"
@click="item.isExpanded = !item.isExpanded">
...
<p v-if="item.isExpanded">...</p>
</div>
<div
v-for="item in list"
@click="item.isExpanded = !item.isExpanded">
...
<p v-if="item.isExpanded">...</p>
</div>
4 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
Default values would need to be generated somehow
18 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
I think that would be unexpected behavior for a lot of use cases
18 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
form?.name. I assume you had it there because originally you had a possibly undefined form.name. After initializing your ref, I removed the question mark in my reproduction because form.name always exists.
18 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
Oh, the issue is the question mark
18 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
Silly question, but have you tried restarting your dev server? Sometimes it gets messed up by certain project changes
18 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
Yeah I have it working in the browser. No errors
18 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
Unfortunately I can't reproduce. That exact code works fine on my machine
18 replies
NNuxt
Created by Insight on 6/17/2024 in #❓・help
ERROR: Invalid assignment target when using a type in ref
v-model requires a valid ref target. In your example, form is of type Ref<Test | undefined>. Initializing a value would solve your problem:
const form = ref<Test>({name: '', age: 0});
const form = ref<Test>({name: '', age: 0});
18 replies