0

I have a Icon.vue file that looks as follows :

<template>
    <div class="book-item Icon--container Icon--{{active}}">
        <a href="{{slug}}">
            <img v-bind:src="path" transition="fadein" class="img-responsive"/>
        </a>
        <template v-if="name">
          <div class="info">
            <h4>{{name}}</h4>
          </div>
        </template>
        <template v-if="remove">
          <div class="delete">
            <a href="#">
              <i class="fa fa-trash"></i>
            </a>
          </div>
        </template>
        <template v-if="edit">
          <div class="edit">
            <a href="#" class="cta purple">Edit</a>
          </div>
        </template>
        <template v-if="view">
          <div class="view">
            <a href="#" class="cta purple">View</a>
          </div>
        </template>
  </div>
</template>

<script>
export default
{

  props:{
    info: {},
    remove: {},
    edit: {},
    view: {},
    active: {default:'show'},
    path: {default:''},
    name: {default:'Icon name'},
    slug: {default:'#'},
  },
  data: function() {
    return {}
  },
  methods:{},
  events: {},
  ready:function(e)
  {

  },
  created:function(e)
  {

  }

};
</script>

Also availble on pastebin

As you can see, There is some logic in there for the following :

  • name
  • remove
  • edit
  • view

I am using Laravel and passing variables from my blade template, But how do I set the if to true within the blade template.

For example :

<icon path="{{url('img/admin/add.png') }}" name="" remove="remove"></icon>

Does not add the remove logic. How do I go about doing that, If possible?

Thanks

1 Answer 1

1

To add logic from a component first you need to bind an event to an element from this component and then leverage the use of methods inside it (https://vuejs.org/guide/events.html).

The template should look something like:

<icon 
path="{{url('img/admin/add.png') }}" 
name="" 
v-on:click="remove"></icon>

And inside the script:

methods: {
  remove: function () {
    // Do something to remove
  }
}

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.