I am terribly new to Vue, so forgive me if my terminology is off. I have a .NET Core MVC project with small, separate vue pages. On my current page, I return a view from the controller that just has:
@model long;
<div id="faq-category" v-bind:faqCategoryId="@Model"></div>
@section Scripts {
<script src="~/scripts/js/faqCategory.js"></script>
}
Where I send in the id of the item this page will go grab and create the edit form for. faqCategory.js
is the compiled vue app. I need to pass in the long
parameter to the vue app on initialization, so it can go fetch the full object. I mount it with a main.ts
like:
import { createApp } from 'vue'
import FaqCategoryPage from './FaqCategoryPage.vue'
createApp(FaqCategoryPage)
.mount('#faq-category');
How can I get my faqCategoryId
into my vue app to kick off the initialization and load the object? My v-bind
attempt seems to not work - I have a @Prop(Number) readonly faqCategoryId: number = 0;
on the vue component, but it is always 0
.
My FaqCategoryPAge.vue script is simply:
<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { Prop } from 'vue-property-decorator'
import Card from "@/Card.vue";
import axios from "axios";
import FaqCategory from "../shared/FaqCategory";
@Options({
components: {
Card,
},
})
export default class FaqCategoryPage extends Vue {
@Prop(Number) readonly faqCategoryId: number = 0;
mounted() {
console.log(this.faqCategoryId);
}
}
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…