javascript - 通过 PHP 在 HREF 中的 Vue.js 数据
问题描述
如何将 vue DATA 的结果传递给 PHP。我尝试过这种方式,但是当我看到 HREF (href = $ where $ name) 中的链接时,它给了我一个奇怪的字符串,而不是我从 VUE 代码中获得的 url。相反,如果我输入: href = "$ where $ name" 或 v-bind: href = "$ where $ name" 而不是我得到没有表的白屏。我怎样才能解决这个问题并能够在 href 中放置正确的链接?
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label v-on:click="giallo()" class="btn btn-secondary active">
<input type="radio" name="options" id="option1" autocomplete="off" checked> Giallozafferano
</label>
<label v-on:click="benedetta()" class="btn btn-secondary">
<input type="radio" name="options" id="option2" autocomplete="off"> Fatto in Casa da Benedetta
</label>
<label v-on:click="nonna()" class="btn btn-secondary">
<input type="radio" name="options" id="option3" autocomplete="off"> Ricette della nonna
</label>
</div>
</div>
$sql = "SELECT id,scadenza,nome,quantita,tipoMisura,categorieP,categorieD FROM Prodotti WHERE utente = '$us' ORDER BY scadenza";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0){
echo "<table class='top table table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th scope='col'>Ricetta</th>";
echo "</tr>";
echo"</thead>";
echo"<tbody>";
}
while ($row = mysqli_fetch_assoc($result)) {
$name=$row['nome'];
$where="{{dove}}";
echo "<td> <a target='_blank' href='$where$name'>Found recipe </a> </td>";
echo "</tr>";
}
//VUE CODE
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
dove: "https://www.giallozafferano.it/ricerca-ricette/"
},
methods : {
giallo: function(){
this.dove="www.giallozafferano.it/ricerca-ricette/";
},
benedetta: function(){
this.dove="https://www.fattoincasadabenedetta.it/?s=";
},
nonna: function(){
this.dove="https://www.ricettedellanonna.net/?s=";
}
}
});
</script>
解决方案
首先你应该使用:href
,然后你的 html 就像:
<a target='_blank' :href='{{dove}}yourstringinname'>Found recipe </a>
我认为问题是您的第二个字符串与 Vue 作为字符串不匹配,您应该将其作为 Vue 的字符串插入:
<a target='_blank' :href='{{dove}} + `yourstringinname`'>Found recipe </a>
在 PHP 中像:
<a target='_blank' :href='$where + `$name`'>Found recipe </a>
就我现在而言,Vue 应该在浏览器控制台中放置错误,因此您可以使用控制台对其进行调试。
推荐阅读
- javascript - 过渡组vue中的过渡效果在列表项的值更改时生效
- laravel - 当另一个已经存在时如何不接受自定义参数
- rxjs - 等待导航结束,然后使用 ngrx 和 rxjs 发送一个操作
- drools - Drools 中存在条件
- reporting-services - 预览报告中的 SSRS 缺少单元格值
- javascript - 获得跨度索引后,如何突出显示选定的跨度并打印选定的文本?
- java - 如何升级 Spring Tool Suite 版本而不是重新安装?
- reactjs - 使用未定义的选择器
- python - GitPython获取开始sha1和结束sha1之间范围内的所有提交
- r - 申请R中文件夹中的pdf文件