如何修复laravel&;我的项目中的vue.js错误
我得到了显示测验页面的应用程序。代码中的示例测试应该显示给用户,但是我似乎无法在laravel中将主页和vue.js链接在一起 我已经能够在一个文件中在notepad++上运行它,但是当我把它带到我的laravel项目中时,它就不工作了。因为它需要在两个不同的文件中 PHP代码:如何修复laravel&;我的项目中的vue.js错误,laravel,vue.js,Laravel,Vue.js,我得到了显示测验页面的应用程序。代码中的示例测试应该显示给用户,但是我似乎无法在laravel中将主页和vue.js链接在一起 我已经能够在一个文件中在notepad++上运行它,但是当我把它带到我的laravel项目中时,它就不工作了。因为它需要在两个不同的文件中 PHP代码: <h1>{{ quiz.title }}</h1> <!-- index is used to check with current question index
<h1>{{ quiz.title }}</h1>
<!-- index is used to check with current question index -->
<div v-for="(question, index) in quiz.questions">
<!-- Hide all questions, show only the one with index === to current question index -->
<div v-show="index === questionIndex">
<h2>{{ question.text }}</h2>
<ol>
<li v-for="response in question.responses">
<label>
<!-- The radio button has three new directives -->
<!-- v-bind:value sets "value" to "true" if the response is correct -->
<!-- v-bind:name sets "name" to question index to group answers by question -->
<!-- v-model creates binding with userResponses -->
<input type="radio"
v-bind:value="response.correct"
v-bind:name="index"
v-model="userResponses[index]"> {{response.text}}
</label>
</li>
</ol>
<!-- The two navigation buttons -->
<!-- Note: prev is hidden on first question -->
<button v-if="questionIndex > 0" v-on:click="prev">
prev
</button>
<button v-on:click="next">
next
</button>
</div>
</div>
<div v-show="questionIndex === quiz.questions.length">
<h2>
Quiz finished
</h2>
<p>
Total score: {{ score() }} / {{ quiz.questions.length }}
</p>
</div>
</div>`
Vue.js code:
'// Create a quiz object with a title and two questions.
// A question has one or more answer, and one or more is valid.
var quiz = {
title: 'My quiz',
questions: [
{
text: "Question 1",
responses: [
{text: 'Wrong, too bad.'},
{text: 'Right!', correct: true},
]
}, {
text: "Question 2",
responses: [
{text: 'Right answer', correct: true},
{text: 'Wrong answer'},
]
}
]
};
new Vue({
el: '#app',
data: {
quiz: quiz,
// Store current question index
questionIndex: 0,
// An array initialized with "false" values for each question
// It means: "did the user answered correctly to the question n?" "no".
userResponses: Array(quiz.questions.length).fill(false)
},
// The view will trigger these methods on click
methods: {
// Go to next question
next: function() {
this.questionIndex++;
},
// Go to previous question
prev: function() {
this.questionIndex--;
},
// Return "true" count in userResponses
score: function() {
return this.userResponses.filter(function(val) { return val }).length;
}
}
});
{{quick.title}
{{question.text}
{{response.text}
上
下一个
测验结束
总分:{{score()}/{{quick.questions.length}
`
Vue.js代码:
“//创建一个带有标题和两个问题的测验对象。
//一个问题有一个或多个答案,一个或多个答案是有效的。
变量测验={
标题:“我的测验”,
问题:[
{
案文:“问题1”,
答复:[
{text:'错了,太糟糕了。},
{text:'Right!',correct:true},
]
}, {
案文:“问题2”,
答复:[
{文本:'正确答案',正确:正确},
{文本:'错误答案'},
]
}
]
};
新Vue({
el:“#应用程序”,
数据:{
小测验:小测验,
//存储当前问题索引
问题索引:0,
//为每个问题初始化为“false”值的数组
//它的意思是:“用户是否正确回答了问题n?”“否”。
userResponses:Array(quick.questions.length).fill(false)
},
//视图将在单击时触发这些方法
方法:{
//转到下一个问题
下一步:函数(){
这个.questionIndex++;
},
//转到上一个问题
prev:function(){
这是一个问题索引--;
},
//在userResponses中返回“true”计数
分数:函数(){
返回this.userResponses.filter(函数(val){return val}).length;
}
}
});
应向用户显示问题选择答案单击下一步,选择下一个答案,然后测验结果将显示给用户。在刀片模板中使用vue字符串插值时使用
@{}
,因为刀片使用{}
作为自己的字符串插值。参考:谢谢,这在一定程度上起了作用。。。。现在,应用程序只在web页面上显示了{{}方面,在blade模板中使用它时,使用vue字符串插值的{code>{{},因为blade使用{}
作为自己的字符串插值。参考:谢谢,这在一定程度上起了作用。。。。现在,应用程序只在网页上显示@{}方面