"Enhance Your Vue Experience with CKEditor's External Link

I am currently engaged in a Vue project that employs ckeditor within one of its components. My goal is to configure hyperlinks so that they open in a new tab whenever an external link is detected.

Based on the documentation, I understand that achieving this involves setting up an editorConfig object within the data property of the instance.

Below is the code snippet showcasing what I have implemented:

<template>
  <div @click="toggleEdit">
    <h3>Program Body</h3>
    <div v-if="!editing" v-html="active.body" />
    <ckeditor :config="editorConfig" :editor="editor" v-if="editing" v-model="form.body" />
    <div v-if="editing" class="row row__end padding__sm">
      <button class="btn btn__cancel" @click.stop="cancelUpdate">Cancel</button>
      <button class="btn btn__green" @click.stop="updateProgram">Update</button>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex";
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
export default {
  props: ["active", "user"],
  data() {
    return {
      editor: ClassicEditor,
      editorConfig: {
        link: {
          addTargetToExternalLinks: true
        }
      },
      permissions: ["admin", "marketing"],
      editing: false,
      form: {
        formObject: "programs",
        formAction: "edit",
        _id: this.active._id,
        body: this.active.body
      }
    };
  },

Even though I verified that the ckeditor tag uses the config by adjusting other properties, it fails to add any attributes to links that begin with http:// or https://.

Your assistance in resolving this issue would be highly appreciated.

Answer №1

Ensure you are using the latest version of ckeditor/ckeditor5-vue to resolve your issue. For detailed installation guidelines, please visit https://www.npmjs.com/package/@ckeditor/ckeditor5-vue/v/1.0.1

Here is a simplified codepen showcasing this functionality with version 1.0.1 https://www.npmjs.com/package/@ckeditor/ckeditor5-vue

https://codepen.io/twickstrom/pen/rNOGZYb

Take a look at the pen, highlight a word, insert a link and check the source, there you go! The _target attribute will be added.

Below is the BASIC code snippet.

Main JS

Vue.use(CKEditor);

Component

<ckeditor :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>

data: {
  editor: ClassicEditor,
  editorData: '<h1>Title</h1><p>Content of the editor.</p>',
  editorConfig: {
    link: {
      addTargetToExternalLinks: true
    }
  }
}

If even after confirming the version you encounter issues, I recommend stripping down unnecessary elements and simplifying until you locate the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to disable a row using ag-grid components?

Recently, while working with ag-grid, I came across documentation on how to disable a column (https://www.ag-grid.com/documentation-main/documentation.php). However, I couldn't find any information on how to disable just one specific row after going t ...

Setting a default date dynamically for v-date-picker in the parent component, and then retrieving the updated date from the child component

I'm working with a custom component that utilizes the v-date-picker in various instances. My goal is to have the ability to dynamically set the initial date from the parent component, while also allowing the date to be modified from the child componen ...

The TypeScript rule in the project-specific .eslintrc.js file is not being applied as expected

Currently, I am following a tutorial on Ionic/Vue 3 which can be found here. However, when I try to serve the project, I encounter the following error: https://i.stack.imgur.com/k4juO.png It appears that my project-level .eslintrc.js file is not being ap ...

How can I retrieve the object returned by an external API in VueJS?

I recently integrated the hcaptcha widget into my login component by utilizing the following package: https://github.com/hCaptcha/vue-hcaptcha. The challenge is functioning correctly on the front end. Upon inspecting the response object in the network tab ...

Having trouble initializing the canvas with fabric.js and Vue.js, as the function this.lowerCanvasEl.getContext is not recognized

When attempting to initialize a canvas in a VueJS component, I encountered an issue. Here is an example: https://jsfiddle.net/eywraw8t/55338/ I tried initializing the canvas in the mounted hook, ensuring that the DOM is available. Fabric seems to be worki ...

Vue's beforeEnter does not function as expected when defined for child routes within routes

Currently, I am working with vue 2.6.10 and have defined my routes in vue's router.js as shown below: Vue.use(Router) const router = new Router({ mode: "history", base: process.env.BASE_URL, routes: [ { path: '/login', ...

When initializing a Vue application using the command 'vue create hello-world', the './fs' module is not found

After spending the last 3-4 hours trying to work with Vue, I'm finding it incredibly challenging just to get it up and running. I've been following the documentation provided here: https://cli.vuejs.org/guide/creating-a-project.html#vue-create ...

Sharing a value across two separate Vue components

Currently, I am in the process of developing an application using vue.js and have encountered a specific issue that I need assistance with. My challenge involves transferring a value between two components that are not directly related to each other. Essen ...

The default export (imported as 'VueGridLayout') from 'vue-grid-layout' could not be located

I recently integrated Vue grid layout into my Vue application and encountered an error message. Despite following the documentation on their website diligently, I still faced this issue. The error message reads as follows: "export 'default&apo ...

The datepicker in Vuetify is failing to display any dates

My date picker modal expands correctly, but the dates are not showing up. https://i.stack.imgur.com/azC1w.png The datepicker functions perfectly on the Codepen demo, displaying the dates as expected. However, when I try to implement the same code in my ap ...

Link the index value of a v-for loop to the id of a newly created component

I need to create components in a loop within my Vue app, but I want each component to have a unique id value like "board-1" based on the index of the loop. Just like how I did it with v-bind:key="component-${block._uid}". How can I make this happen? < ...

Is it possible to create an array of strings in Vue Bootstrap by separating them with commas from a

How can I extract both number and alpha strings from a text area in Vue Bootstrap and then save them into an array? The strings are separated by commas when entered. Additionally, it would be great if these strings could appear as 'pills' or tags ...

Identifying when a fetch operation has completed in vue.js can be accomplished by utilizing promises

Currently, I am facing a dilemma in my Vue.js application. I am making an API call within the created() hook, but there are certain tasks that I need to trigger only after the API call has been completed. The issue is that this API call usually takes aroun ...

What is the best way to manage URL data between a domain and hashtag using Vue Router?

I am currently developing a project using vue-cli, vue router, and node.js. The routing in Vue is set to hash mode so that users can easily navigate to specific pages by copying and pasting URLs or typing from memory without encountering any errors. Howeve ...

When it comes to entering text in a text input or textarea within a large module in Vue.js, taking

While filling out my large form, I noticed a delay in rendering whenever I typed quickly into the input boxes. <b-form-input v-model="paymentItems.tierStepUPYear" type="text"></b-form-input> ...

Tips for resolving a blank screen issue when attempting to render components using the `:is="component"` attribute

Working with NativeScript-Vue for Android, my goal is to display a component based on button taps. To achieve this, I am utilizing this plugin which helps in integrating a global SideDrawer for smooth navigation. The buttons within the SideDrawer are used ...

I'm encountering an issue where Bulma is taking precedence over the CSS of my Vue3

In my Vue CLI 3 project, I'm utilizing Bulma and have included the import in the 'index.js' file like so: import { createApp } from 'vue' import App from './App.vue' import router from './router' require('@ ...

Unlocking fashion with $refs: A step-by-step guide

After using console.log(this.$refs['block' + row + column]);, I confirmed that I can successfully access the HTML element it refers to. https://i.stack.imgur.com/7KYqB.png However, when attempting to access the element's style using variou ...

Interactive Vue components with dynamic children and sub-children

In my Vue application, I have a component called Address.vue which contains a child component called Contact.vue. One address can contain multiple components What I have accomplished: I have implemented the functionality in the Address.vue component t ...

Is it possible to nest axios post requests within another axios post request?

Can someone assist me with getting the session ID from the API to utilize it as a part of my input for an Axios POST request in order to retrieve user information? Despite double-checking my code thoroughly, I keep encountering a session expired error. Any ...