简体   繁体   English

HREF 中的 Vue.js 数据通过 PHP

[英]Vue.js data in HREF through PHP

How do I pass the result of the vue DATA into PHP.如何将 vue DATA 的结果传递给 PHP。 I tried this way but when I see the link in HREF (href = $ where $ name) it gives me a strange string and not the url one I get from the VUE code.我尝试过这种方式,但是当我看到 HREF (href = $ where $ name) 中的链接时,它给了我一个奇怪的字符串,而不是我从 VUE 代码中得到的 url 字符串。 Instead if I put: href = "$ where $ name" or v-bind: href = "$ where $ name" instead I get the white screen WITHOUT table.相反,如果我输入: href = "$ where $ name" 或 v-bind: href = "$ where $ name" 而不是我得到没有表的白屏。 How can I solve this problem and be able to put the right link in the href?我怎样才能解决这个问题并能够在 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>

First of all you should use :href , then your html would be like:首先你应该使用:href ,然后你的 html 就像:

<a target='_blank' :href='{{dove}}yourstringinname'>Found recipe </a>

I think problem is that your second string is not matched for Vue as string, you should insert it as string for Vue:我认为问题是您的第二个字符串与 Vue 作为字符串不匹配,您应该将其作为 Vue 的字符串插入:

<a target='_blank' :href='{{dove}} + `yourstringinname`'>Found recipe </a>

In PHP like:在 PHP 中,如:

<a target='_blank' :href='$where + `$name`'>Found recipe </a>

As far as i now Vue shoud place errors in browser console, so you can debug it with console.就我现在而言,Vue 应该在浏览器控制台中放置错误,因此您可以使用控制台对其进行调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM