【问题标题】:How do I navigate links in the <a> tag using a script?如何使用脚本导航 <a> 标记中的链接?
【发布时间】:2018-10-08 23:26:00
【问题描述】:

我无法在此代码中创建导航链接。这不是我的代码,但我需要制作工作网站。我不知道如何将变量(页面名称,vue-file)从脚本传递到 html-tag 。请帮忙!提前谢谢!

这是网站的主页,在这个页面上我需要点击文本“阅读更多...”并转到另一个页面。

我试过了:

&lt;nuxt-link :to='card.link' v-for="card in cards" :key="card.image"&gt;Read more...&lt;/nuxt-link&gt;

改为标记a,但出现错误...

-<template>
  <div>
    <div class="subtitle">
      <h2>Some text</h2>
      
      <div class="text"> 
        Some text
      </div>

      <div class="main-tasks">
        <img class="photo" src="images/index/act59440c9c55367.jpg" alt="Univercity"> 
        <div class="subtitle2">
          <h2>Some text</h2>
        </div>
        <div class="tasks"> 
          Some text
        </div>
      </div>
    </div>
    <div class="card-wrap">
      <div class="card" v-for="card in cards" :key="card.image">
        <h2 class="card-title">{{card.title}}</h2>
        <img class="img-card" :src="'/images/index/' + card.image + '.png'" alt="npo">
        
        <p class="card-description">{{card.description}}</p>
        <br>
        <a href="#" class="button-go">Read more...</a> <!-- Here I need to pass the values in the form of page names -->
      </div>
    </div>
  </div>
</template>

<style>
.text{
max-width: 100%;
padding: 0;
text-align: left;

}
.tasks{
max-width: 100%;
margin: 0;
}
.card {
	width: 100%;
	margin: -1em 0 -1em;
	padding: 10px 10px;
	padding-right: 1.25rem;
	padding-left: 1.25rem;
	text-align: center;

	}
.card-title {
	margin: 2em 0 1em;
	padding: 20px 10px;

	text-align: center;

	color: white;
	border-radius: 3px;
	background-color: rgb(85, 85, 87);
	}

.img-card {
	max-width: 60%;
	}
  
.description {
	margin-bottom: 1rem;
	text-align: center;
	opacity: .7;
	color: grey;
	}
.card-wrap {
	display: flex;

	margin-right: .5rem;
	margin-bottom: 2rem;
	margin-left: .5rem;

	text-align: center;
	text-decoration: none;
	letter-spacing: .025em;

	background-color: white;
	}

.button-go {
	font-weight: 700;

	padding: .8em 1em calc(.9em + 2px);

	text-decoration: none;

	color: white;
	border-radius: 3px;
	background: rgb(101, 161, 218);
	}


</style>
<script>
export default {
  data () {
    return {
      cards: [
        {
          link: 'rnd',
          title: 'R&D',
          image: '1',
          description: 'Some text'
        },
        {
          link: 'develop',
          title: 'Development',
          image: '2',
          description: 'Some text'
        },
        {
          link: 'edu',
          title: 'Education',
          image: '3',
          description: 'Some text'
        }
      ]
    }
  }
}
</script>

【问题讨论】:

    标签: node.js vue.js nuxt.js


    【解决方案1】:

    我解决了任务:

    &lt;a :href="card.link" class="button-go"&gt;Read more...&lt;/a&gt;

    很简单。

    【讨论】:

      【解决方案2】:

      参见&lt;nuxt-link&gt; 组件:

      https://nuxtjs.org/api/components-nuxt-link/

      <template>
       <div>
        <h1>Home page</h1>
         <nuxt-link to="/about">About</nuxt-link>
      </div>
      

      我不熟悉 nuxt。刚刚找到它。可能会有所帮助

      【讨论】:

      • 是的,我找到了这个标签,但我无法编写正确的代码。出现错误,项目不成立。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      相关资源
      最近更新 更多